oracle竖表转横表
时间:2011-10-19
来源:互联网
student表中数据:
name type
--------------------------
大黄 3
小白 1
多多 1
大黄 1
大黄 2
小宝 1
小宝 2
小宝 3
查询结果:
type=1 type=2 type=3
------------------------
小白 null null
多多 null null
大黄 大黄 大黄
小宝 小宝 小宝
作者: yzncong 发布时间: 2011-10-19
SQL code
select max(case when type=1 then name end) t1, max(case when type=2 then name end) t2, max(case when type=3 then name end) t3 from student group by name
作者: noteasytoregister 发布时间: 2011-10-19
“值过多”
什么意思?
什么意思?
作者: yzncong 发布时间: 2011-10-19
建议用decode
select t.name,
max(decode(t.type,'1',t.type,null)) type1,
max(decode(t.type,'2',t.type,null)) type2,
max(decode(t.type,'3',t.type,null)) type3
from student t
group by t.name
select t.name,
max(decode(t.type,'1',t.type,null)) type1,
max(decode(t.type,'2',t.type,null)) type2,
max(decode(t.type,'3',t.type,null)) type3
from student t
group by t.name
作者: stu202060510 发布时间: 2011-10-19
晕,看错了。下面这个
select
max(decode(t.type,'1',t.name,null)) type1,
max(decode(t.type,'2',t.name,null)) type2,
max(decode(t.type,'3',t.name,null)) type3
from test t
group by t.name
select
max(decode(t.type,'1',t.name,null)) type1,
max(decode(t.type,'2',t.name,null)) type2,
max(decode(t.type,'3',t.name,null)) type3
from test t
group by t.name
作者: stu202060510 发布时间: 2011-10-19
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28