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
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
Post a Comment