现有数据库为每个煤矿企业的应淘汰和已淘汰设备数目,并且每个煤矿的属性(国有重点、地方、乡镇)也有相应字段,现在想通过一条语句查询到下面这种格式的数据(因为涉及到.net中的表格控件,所以尽量就用一条语句啦),求问该怎么写SQL语句呢??谢谢谢谢~~~
解决方案 »
- 关于oracle 11g 如何更改字符集合
- weblogic集群 session粘性问题
- Enterprise Manager中,如何使用OS用户
- 能不能不安装ORACLE客户端而连接ORACLE数据库?
- exp/imp, snatshop在oracle online文档的那个地方?
- 如何实现rownum和order by 的问题???
- Oracle安装问题!
- 紧急求救!!!关于删除用户的问题!!
- oracle表设计
- orcle sql developer连接本地oracle失败 测试失败(如何解决)
- 急急急!!!! oracle导入的dmp文件,出现字符集完成导入,数据库中没有数据,求大神指点,在线等
- oracle 哪本书比较好啊
with t as
(select sum(case when sx1='应淘汰' and sx2='国有重点' then sl else 0 end) GYZD1,
sum(case when sx1='应淘汰' and sx2='国有地方' then sl else 0 end) GYDF1,
sum(case when sx1='应淘汰' and sx2='乡镇煤矿' then sl else 0 end) XZMK1,
sum(case when sx1='已淘汰' and sx2='国有重点' then sl else 0 end) GYZD2,
sum(case when sx1='已淘汰' and sx2='国有地方' then sl else 0 end) GYDF2,
sum(case when sx1='已淘汰' and sx2='乡镇煤矿' then sl else 0 end) XZMK2
yourTable)
select GYZD1+GYDF1+XZMK1 as HJ1,GYZD1,GYDF1,XZMK1,GYZD2+GYDF2+XZMK2 as HJ2,GYZD2,GYDF2,XZMK2
from t;
select
case when 设备类型 = 淘汰设备 and 企业类型 = 国有重点 then
xxxxxx
end,
case when 设备类型 = 淘汰设备 and 企业类型 = 国有地方 then
xxxxxx
end,
...以此类推
from table group by 设备类型,企业类型