sql - How to optimise query containing subqueries from same table? -


I am very new to MS SQL

I have a table that includes all comments from customer As well as admin

[CommDate]) [TicketId], [t0]. [TransactionID], (SELECT MIN ([t1]. [CommDate]) [DBO]. [Comments History] AS [T1] WHERE [T1]. [TTIID] = [T.]. [TTIID]) and ( [T1]. [Like commented '% client%'] [Asked midday], (SELECT MIN ([T2]. [CommDate]) [Comments] History [T2] where ([T2]. [ Ticket ID] [T0]. [Ticket] and (No ([T2]. [Like commented '% client%']) AS [ResponseManadat] FOR [DBO]. [Comments History] AS [T. ] Where (converter (DATE, [t]]. [Comet]] gt; = DATEAD (mm, -1, gaterate ()) and [T] [TTIID] is not [T] [TTI] [TTIID] DESC, [T.]. [Command]

I have applied the index, but since The non-unique content of the column is not very helpful.

Is there any other way to write these types of questions, or should I consider reducing the table itself?

returns the above query results, but is very slow, I want to know that my query op Is not optimized or is the selection of the choice of my table wrong?

Enter image details here Comments [history] [[ID] [IT] [int] identification (1,1) null, [comet] [daytime] null constant [df_commentsHistory_CommDate] DEFAULT (Dot), [comment] [varchar] (255) NULL, [Comments] [varchar] NULL (max), [TransactionID] [float] NULL, [splitnumber] [varchar] (50) NULL, [MfrId ] [Int] NULL, [[show original] [bit] null, [showwire] [bit] null, [isspons] [beet] null, [crust eme ] [Primary] [primary]

You did not provide any data to test, but my intuition is to run sub-questions as with sections will run faster Because they will run once and the main result will be in the set of resistance to running for each line. As [Content]] [DBA] [Comments] as history [T1] as [T1] where [T1] [T1] [MT] [T1] as [customer]. [T1]. [Like comment '% client%'] by the group [T1]. [Ticket ID], as a liability (SELECT [T2]. [Ticket ID], Min ([T2]. [CommDate] from AS [Commodate] [DBO] [Comments] AS [T2] where (not [T2]. [Commented as '% client%']] [T2] by group [Ticket ID ], [CommDate2], [t0]. [TicketId], [T.]. [TransactionID], [T1]. [CommDate] AS [AskedMinDate] [Convert Convert] , [T2]. [Commodate] AS [ResponseMinDate] [TCT] [T] on [T1] at [T1]. [TTIID] = [T.]. [Ticket ID] [T2] [T2ID] = [T0] at [T2]. [Ticket] where [converter (date, [T.]] [CommDate] gt; = DATEAD (mm, -1) Order By [T]] [Ticket ID] DESC, [T.] [Commodity];

GETDATE ()) and ([T.]. [Ticket ID] One more thing that accelerates is that you can use the equality operator instead of as operator, like [comment] = 'customer' . It depends on when the from the comment column Amgri fully 'client' is , then it is to note the client or not. If it is, you can use the equality operator. If not, then the column always starts with starts with 'client' or this value is in the same condition so that you can use or like < / em> LEFT ([CommentFrom], 6) = 'Client' .

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -