February 25, 2016 at 10:52 pm
HI friends,
Is there any way to rewrite this query from performance point of view -
DECLARE @var1 as DECIMAL(10,3)
SELECT @var1 = (( SELECT TOP 1 col1 FROM ( SELECT TOP 50 PERCENT col1
FROM ( SELECT col1, col2,
ROW_NUMBER() OVER (Partition BY col2 ORDER BY col1 ASC)as RASC,
ROW_NUMBER() OVER (Partition BY col2 ORDER BY col1 DESC)as RDESC
FROM #temp
)X
WHERE col1 IS NOT NULL
ORDER BY col1)AS A
ORDER BY col1 DESC
Any help would be appreciated.
many thanks in advance
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
February 26, 2016 at 7:34 am
The first thing I notice is that you are calculating two ROW_NUMBERs that you never use.
You also have unbalanced parentheses.
If you want any more than that, I suggest that you follow the advice that you've included a link to in your signature. For performance questions, it also helps to include the actual query plan.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
February 26, 2016 at 10:19 am
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply