在postgresql的select查询中排列我的结果?

在postgresql的select查询中排列我的结果?,sql,postgresql,Sql,Postgresql,我有一个问题: select c1,q1,c2,q2,c3,q3,c4,q4 from mxm 结果是: 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

我有一个问题:

select c1,q1,c2,q2,c3,q3,c4,q4 from mxm
结果是:

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
但是我想要这样的输出:

9103  4
9114  3.3   
9197  1.9   
B9151 3000 
9103   15   
9107   8.6   
9118   8.3   
B9100  130.6

等等。。。。这在postgresql中是可能的吗?

如果您想让它们按那个顺序排列,这有点棘手。假设您在
mxm
中没有适当的id来按顺序标识行:

with t as (
      select row_number() over (order by ??) as seqnum, mxm.*
      from mxm
)
select c, q
from ((select c1, q1, seqnum, 1 as ordering from t) union all
      (select c2, q2, seqnum, 2 from t) union all
      (select c3, q3, seqnum, 3 from t) union all
      (select c4, q4, seqnum, 4 from t)
     ) cq
order by seqnum, ordering;

??
用于指定记录原始顺序的列。

如果您希望按该顺序排列,则有点棘手。假设您在
mxm
中没有适当的id来按顺序标识行:

with t as (
      select row_number() over (order by ??) as seqnum, mxm.*
      from mxm
)
select c, q
from ((select c1, q1, seqnum, 1 as ordering from t) union all
      (select c2, q2, seqnum, 2 from t) union all
      (select c3, q3, seqnum, 3 from t) union all
      (select c4, q4, seqnum, 4 from t)
     ) cq
order by seqnum, ordering;
??
用于指定记录原始顺序的列