单行的数据怎么转置啊,互不相干那种
sql吧
全部回复
仅看楼主
level 1
小熊比个耶🐼
楼主
像图上这样的,怎么变成一列啊?想看具体语句,转不过弯了,谢谢
2022年09月13日 15点09分
1
level 1
生活要二才有爱
select a from t
union all
select b from t
...
2022年09月14日 09点09分
2
小熊比个耶🐼
谢谢,但是我那个代码超长,union的话代码长度太长了,casewhen有没有可能实现呢?
2022年09月15日 05点09分
生活要二才有爱
@小熊比个耶🐼
case when用来行转列,你这是列转行
2022年09月15日 09点09分
贴吧用户_GNyt134
俦俦 学-TensorFlow-到-siki学院 -------特镣
2022年09月16日 07点09分
level 13
永远的Key社
用pivot
2022年09月23日 02点09分
3
level 11
adqh42
如果要写case when的话
把你的表cross join 一张自然数表,做成下面这个样子
i a b c d
1 4 5 6 7
2 4 5 6 7
3 4 5 6 7
4 4 5 6 7
...
select
(case when i=1 then a
when i=2 then b
when i=3 then c
...
else null end)as col
from t1;
如果需要转的列特别多或者数量不固定的话,可以写动态SQL
2022年09月29日 11点09分
5
level 1
生米煮e1成熟饭
鬃氨 学-各种-插件-开发-到-siki学院 -------徘琳烙加录渡狗檀细狙肥辰踊绽淖钒
2022年09月29日 12点09分
6
1