MYSQL Sorting by alternative sets of results by a column -
suppose have result set column_id: 1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4
i have tried usual "order asc" , returned me:
1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4
but required result set is:
1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4
also used "group by" function, since used aggregation functions returns me 1st set of results: 1,2,3,4
please me solving this.
you can use user defined variables desired result set
select column_id ( select column_id, @r:= case when @g = column_id @r + 1 else 1 end seq, @g:= column_id table1 cross join (select @g:= null,@r:=0) t order column_id ) t1 order seq,column_id
Comments
Post a Comment