SQL server 2005 grouping values, display only changes -


posting again i've made updates.

i'm trying group set of values, want display values if there change.

imagine value fluctuating, ranging 1, 4, 3, 1, 1 , 1 again.

some example data

value | date_loaded |    1   |  2012-03-07 |   1   |  2012-03-06 |   1   |  2012-03-05 |   3   |  2012-03-04 |   4   |  2012-03-03 |   1   |  2012-03-02 | 

i want display each of values in order of fluctuated, group them together. see in order, 1, 4, 3, 1, rather 3 1's recently.

so display latest value, it's earliest date, e.g.

value | date_loaded |    1   |  2012-03-05 |   3   |  2012-03-04 |   4   |  2012-03-03 |   1   |  2012-03-02 | 

what best way go this? possible if statement? if value 1 different value 2, +1 "change" ? therefore i'd able group values "change1", "change2" etc.?

how about:

;with data ( select 1 [value],'2012-03-07' date union select 1,'2012-03-06' union select 1,'2012-03-05' union select 3,'2012-03-04' union select 4,'2012-03-03' union select 1,'2012-03-02' ) ,data2 ( select  [value] ,date ,row_number() on (order (select null)) row1 data ) ,data3 ( select *  , row1 - row_number() on (order [value]) row2 data2 ) select  min([value]) [value] ,min(date) date data3 group [value] - row2 order min(row1) 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -