March 27, 2012 at 4:07 pm
Eugene Elutin (3/27/2012)
...
Try adding this into the original sample data
SELECT 'Jun 1 2011 12:00AM','1','10','20' UNION ALL
The results of the two queries are different.
My query will only work if status never returns to something it was before (as per OP sample data).
If it does, I would try to use "quirky update" method.
There's a way to to even that without a Quirky Update by using the difference between two ROW_NUMBERs that use different partitions.
--Jeff Moden
Change is inevitable... Change for the better is not.
March 28, 2012 at 1:44 am
Jeff Moden (3/27/2012)
Eugene Elutin (3/27/2012)
...
Try adding this into the original sample data
SELECT 'Jun 1 2011 12:00AM','1','10','20' UNION ALL
The results of the two queries are different.
My query will only work if status never returns to something it was before (as per OP sample data).
If it does, I would try to use "quirky update" method.
There's a way to to even that without a Quirky Update by using the difference between two ROW_NUMBERs that use different partitions.
Which is exactly what my query does.
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537March 28, 2012 at 2:12 am
Jeff Moden (3/27/2012)
Eugene Elutin (3/27/2012)
...
Try adding this into the original sample data
SELECT 'Jun 1 2011 12:00AM','1','10','20' UNION ALL
The results of the two queries are different.
My query will only work if status never returns to something it was before (as per OP sample data).
If it does, I would try to use "quirky update" method.
There's a way to to even that without a Quirky Update by using the difference between two ROW_NUMBERs that use different partitions.
Over 25 sec for just over 1 million records, Quirky Update may run faster...
may not.
I guess it's really depends on real situation, if state cannot return back, then grouping is enough, otherwise - row_number or QU, whatever faster for his case.
Viewing 3 posts - 16 through 17 (of 17 total)
You must be logged in to reply to this topic. Login to reply