情况是这样的
我要一张表
BH GZ(工种) RS(人员数量)
PDA03116 注册兽医师 2
PDA03116 注册兽医师 3
PDA03116 无定级兽医 1
PDA03116 中级技工 2
PDA03116 初级技工 1
PDA03116 无定级技工 2
PDA03117 无定级技工 7
...........
...........
想转换成如下形式:
BH j_0(注册兽医师) j_1(注册兽医师) j_2(无定级兽医) j_3(中级技工) j_4(初级技工) j_5(无定级技工)
PDA03116 2 3 1 2 1 2
PDA03117 .... .... ...... ..... ..... 7我用DECODE()函数怎么也没解决这个问题
BH 会重复
请赐教
还有谁有谁有 oracle的performance manager学习资料发一份(另外给分)
EMAIL:
[email protected]
我要一张表
BH GZ(工种) RS(人员数量)
PDA03116 注册兽医师 2
PDA03116 注册兽医师 3
PDA03116 无定级兽医 1
PDA03116 中级技工 2
PDA03116 初级技工 1
PDA03116 无定级技工 2
PDA03117 无定级技工 7
...........
...........
想转换成如下形式:
BH j_0(注册兽医师) j_1(注册兽医师) j_2(无定级兽医) j_3(中级技工) j_4(初级技工) j_5(无定级技工)
PDA03116 2 3 1 2 1 2
PDA03117 .... .... ...... ..... ..... 7我用DECODE()函数怎么也没解决这个问题
BH 会重复
请赐教
还有谁有谁有 oracle的performance manager学习资料发一份(另外给分)
EMAIL:
[email protected]
解决方案 »
- Forms里如何读写multi-line的text item
- 使用sqllder导csv文件数据到oracle的问题,请指教。
- 急等以个关于group by后分组列的顺序问题
- ORACLE SQL关于IN的用法的一个疑问
- 备份数据库的存储过程的问题??
- 十万火急!!关于oracle视图查询
- 如何删除Oracle的归档日志文件啊?
- 初学数据库,数据库语言的简单问题
- 我在ORACLE里使用update...from进行多表更新,为什么报from语法错误“UPDATE A SET A.STATUS = 0 FROM ONE A,TWO B WHERE A.id=B.id”
- oracle 数据库如何提取查询计划,并格式化
- 创建数据库问题
- 创建数据库问题
PDA03116 注册兽医师 3
这两行的"注册兽医师"是一样的?
我要一张表
BH GZ(工种) RS(人员数量)
PDA03116 注册兽医师 3
PDA03116 无定级兽医 1
PDA03116 中级技工 2
PDA03116 初级技工 1
PDA03116 无定级技工 2
PDA03117 无定级技工 7
...........
...........
想转换成如下形式:
BH j_1(注册兽医师) j_2(无定级兽医) j_3(中级技工) j_4(初级技工) j_5(无定级技工)
PDA03116 3 1 2 1 2
PDA03117 .... ...... ..... ..... 7
我用DECODE()函数怎么也没解决这个问题
BH 会重复
请赐教
还有谁有谁有 oracle的performance manager学习资料发一份(另外给分)
EMAIL:
[email protected]
union all
select 'PDA03116' BH,'无定级兽医' GZ,1 RS from dual
union all
select 'PDA03116' BH,'中级技工' GZ,2 RS from dual
union all
select 'PDA03116' BH,'初级技工' GZ,1 RS from dual
union all
select 'PDA03116' BH,'无定级技工' GZ,2 RS from dual
union all
select 'PDA03117' BH,'无定级技工' GZ,7 RS from dual)
select bh,sum(decode(gz,'注册兽医师',rs,0)) "j_1(注册兽医师)",
sum(decode(gz,'无定级兽医',rs,0)) "j_2(无定级兽医)",
sum(decode(gz,'中级技工',rs,0)) "j_3(中级技工)",
sum(decode(gz,'初级技工',rs,0)) "j_4(初级技工)",
sum(decode(gz,'无定级技工',rs,0)) "j_5(无定级技工)" from test
group by bh;
,sum(decode(GZ,'无定级兽医,RS,0)) "j_2(无定级兽医)"
....
from a
group by bh
select Distinct t01,
max(case a when '1' then t03 end) A,
max(case a when '2' then t03 end) B,
max(case a when '3' then t03 end) C,
max(case a when '4' then t03 end) D,
max(case a when '5' then t03 end) E,
max(case a when '6' then t03 end) F,
max(case a when '7' then t03 end) G
from (
select test.*,to_char(rownum) a from test)
group by t01
2 PDA03116 注册兽医师 3
3 PDA03116 无定级兽医 1
4 PDA03116 中级技工 2
5 PDA03116 初级技工 1
6 PDA03117 无定级技工 2
7 PDA03117 无定级技工 7表中的内容:
select Distinct t01,
max(case a when '1' then t03 end) A,
max(case a when '2' then t03 end) B,
max(case a when '3' then t03 end) C,
max(case a when '4' then t03 end) D,
max(case a when '5' then t03 end) E,
max(case a when '6' then t03 end) F,
max(case a when '7' then t03 end) G
from (
select test.*,to_char(rownum) a from test)
group by t01RESULT:
PDA03116 2 3 1 2 1
PDA03117 2 7
CREATE TABLE tt(BH VARCHAR2(20), GZ VARCHAR2(20), RS VARCHAR2(20));
INSERT INTO TT VALUES ('PDA03116', '注册兽医师', 3);
INSERT INTO TT VALUES ('PDA03116', '无定级兽医', 1);
INSERT INTO TT VALUES ('PDA03116', '中级技工', 2);
INSERT INTO TT VALUES ('PDA03116', '初级技工 ', 1);
INSERT INTO TT VALUES ('PDA03116', '无定级技工', 2);
INSERT INTO TT VALUES ('PDA03117', '无定级技工', 7);
COMMIT;
SELECT BH,
MAX(DECODE(GZ, '注册兽医师', RS)),
MAX(DECODE(GZ, '无定级兽医', RS)),
MAX(DECODE(GZ, '中级技工', RS)),
MAX(DECODE(GZ, '初级技工', RS)),
MAX(DECODE(GZ, '无定级技工', RS))
FROM TT
GROUP BY BH
ORDER BY 1;