sql - Arrange my result in select query of postgresql? -
i have query:
select c1,q1,c2,q2,c3,q3,c4,q4 mxm
the result is:
c1 q1 c2 q2 c3 q3 c4 q4 9103 4 9114 3.3 9197 1.9 b9151 3000 9103 15 9107 8.6 9118 8.3 b9100 130.6 9103 3.6 9114 0.6 9197 1.1 b9151 5000
but want output like:
9103 4 9114 3.3 9197 1.9 b9151 3000 9103 15 9107 8.6 9118 8.3 b9100 130.6
and on .... possible in postgresql?
if want them in order, bit tricky. assuming have no appropriate id in mxm
identifying rows in order:
with t ( select row_number() on (order ??) seqnum, mxm.* mxm ) select c, q ((select c1, q1, seqnum, 1 ordering t) union (select c2, q2, seqnum, 2 t) union (select c3, q3, seqnum, 3 t) union (select c4, q4, seqnum, 4 t) ) cq order seqnum, ordering;
the ??
column specifies original ordering records.
Comments
Post a Comment