gpt4 book ai didi

sql - 将我的结果安排在 postgresql 的选择查询中?

转载 作者:行者123 更新时间:2023-11-29 13:54:19 24 4
gpt4 key购买 nike

我有一个问题:

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;

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

关于sql - 将我的结果安排在 postgresql 的选择查询中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35167565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com