sql server - How to select Alternating column values -


i have list data order dcreporttime.

my problem need select row alternating (alarmset/alarmcleared).

pls refer pic below... tq~

**red - no need select.

shift     | locationname       | calarmstate      | dcreporttime --------- ----------------------------------------------------------     5/15/2013 | myq01_ctes_a_lts   | **alarmset**     | 11:12:26 5/15/2013 | myq01_ctes_a_lts   | **alarmcleared** | 11:12:26 5/15/2013 | myq01_ctes_a_lts 5 | alarmcleared     | 11:12:53 5/15/2013 | myq01_ctes_a_lts 5 | alarmset         | 14:57:38 5/15/2013 | myq01_ctes_a_lts 5 | alarmset         | 14:57:43 5/15/2013 | myq01_ctes_a_lts 5 | alarmcleared     | 14:57:43 

example data : here!

try :-

 select  a.shift,a.locationname,a.dcreporttime,a.calarmstate  yourtable  inner join yourtable b  on  a.calarmstate <> b.calarmstate , a.locationname=b.locationname  , a.dcreporttime= b.dcreporttime 

demo in sql fiddle


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -