sql - convert row to column using Pivot without any clause -
i have table below.
i need data below.
i have created 2 temp tables , achieved result this. please me same pivot.
at least wouldn't use pivot that, mind simpler group , row_number:
select userid, max(starttime) starttime, max(endtime) endtime ( select userid, case when startorend = 's' time end starttime, case when startorend = 'e' time end endtime, row_number() on (partition userid order time asc) + case when startorend = 's' 1 else 0 end grp table1 ) x group userid, grp order starttime
the derived table splits time start / end time columns (to handle cases 1 exists) , uses trick row number group s / e items together. outer select groups rows same row.
example in sql fiddle
Comments
Post a Comment