表1product bomid qnt type
a 1 1 压缩机
a 2 1 压缩机
a 3 2 电机
b 4 1 电机
b 5 2 压缩机
b 6 1 电机希望生成product 压缩机1编码 qnt 压缩机2编码 压缩机2数量 电机1编码 电机1数量 电机2编码 电机2数量
a 1 1 2 2 3 2 0 0
b 5 2 0 0 4 1 6 1 请各位高手指点一下,谢谢.
a 1 1 压缩机
a 2 1 压缩机
a 3 2 电机
b 4 1 电机
b 5 2 压缩机
b 6 1 电机希望生成product 压缩机1编码 qnt 压缩机2编码 压缩机2数量 电机1编码 电机1数量 电机2编码 电机2数量
a 1 1 2 2 3 2 0 0
b 5 2 0 0 4 1 6 1 请各位高手指点一下,谢谢.
解决方案 »
- sql的like '%%' 如何理解。。。。。
- 请教 insert /*+append */ table nologging selec * from table_other 这种方式下数据库事务的控制
- Oracle SQL优化问题
- 求SQL 语句一条, 来拿分吧!!!!!!!!!!!!
- 这是一道面试题,谁来看看,解决办法!!!
- 请教一段PL/SQL代码
- 急:请问LogMiner 在哪里能下载?在线等!!
- 我的ora8i中有个两个数据库A、B,我在oem中移去了一个A,在磁盘上A的文件没有删除。现在OEM里面只有B库了,我想把
- Oracle技术官方中文论坛开通了,高兴!
- 连接配置出错,ora-1017
- 高手请进--住址查出编码code
- 提高SQL水平的方式和途径
select 'a' product, 1 bomid ,1 qnt, '压缩机' type from dual union all
select 'a' ,2 ,1 ,'压缩机' from dual union all
select 'a' ,3 ,2 ,'电机' from dual union all
select 'b' ,4 ,1 ,'电机' from dual union all
select 'b' ,5 ,2 ,'压缩机' from dual union all
select 'b' ,6 ,1 ,'电机' from dual )
select product,
sum(case when bomid =1 or bomid=5 then bomid else 0 end ) 压缩机1编码,
sum(case when bomid =1 or bomid=5 then qnt else 0 end ) qnt ,
sum(case when bomid =2 then bomid else 0 end ) 压缩机2编码,
sum(case when bomid =2 then qnt else 0 end ) 压缩机2数量 ,
sum(case when bomid =3 or bomid=4 then bomid else 0 end )电机1编码,
sum(case when bomid =3 or bomid=4 then qnt else 0 end ) 电机1数量,
sum(case when bomid =6 then bomid else 0 end ) 电机2编码,
sum(case when bomid =6 then qnt else 0 end ) 电机2数量
from tb
group by product
只是针对数据,木有太大意义……