oracle列转行问题 - Oracle / 基础和管理
现在一个表中有两列数据
shuliang area
1 025
2 0510
3 0511
4 0512
5 0513
要求是把area字段中的值转换成城市名称,比如025是南京,0510是无锡,0511是镇江,0512是苏州,0512是南通
显示成
南京 无锡 镇江 苏州 南通
1 2 3 4 5
请问sql怎么写啊
SQL code:
select sum(case when area = '025' then shuliang else 0 end) as 南京
,sum(case when area = '0510' then shuliang else 0 end) as 无锡
,sum(case when area = '0511' then shuliang else 0 end) as 镇江
,sum(case when area = '0512' then shuliang else 0 end) as 苏州
,sum(case when area = '0513' then shuliang else 0 end) as 南通
from 表名;
select
case when area='025' then shuliang end 南京,
case when area='0510' then shuliang end 无锡,
case when area='0511' then shuliang end 镇江,
case when area='0512' then shuliang end 苏州,
case when area='0513' then shuliang end 南通
from 表;
select sum(decode(area, '025', 1, 0)) as 南京,
sum(decode(area, '0510', 1, 0)) as 无锡,
sum(decode(area, '0511', 1, 0)) as 镇江,
sum(decode(area, '0512', 1, 0)) as 苏州,
sum(decode(area, '0513', 1, 0)) as 南通
from t
group by area
相关问答:
大家好,我现在把oracle服务器上面的原始文件,下载到本机了.我想在本机访问数据库怎么设置啊.是不是类似可以建立一个什么虚拟服务器来实现.请大家出出主意
引用
大家好,我现在把oracle服务器上面 ......
各位大哥,帮个忙。
下个Oracle for vista 版本的安装试试
10G和11G的
http://www.oracle.com/technology/software/products/database/index.html
------------------------------------------- ......
在系统运行的时候总是有一块磁盘始终闪红灯,进入系统后
#topas查看总是有一块磁盘%BUSY为90%以上,
数据库版本:oracle 9.2.0.7
数据文件挂载的节点:/oradata/pcs/ 逻辑卷号lv04
#lslv -l lv04
......
假设table01 中有 以下资料
emp_no emp_name
------- ------------
0001 TOM
0002 JOHN
0003 MARY
常用电话
而我们要得到以下的OUTPUT (或是各种其他的output)
0001,TOM
0002,JOHN
......
select distinct '1' t1,'2' t2,'3' t3,'4' t4 from table 查出来的结果为
1,2,3,4
我想得以下这样的效果
1
2
3
4
请问一下有什么办法可以解决???
没有好的方法,用union,一条条记录拼接
SQL code:
wi ......