当前位置: 代码迷 >> Oracle技术 >> oracle子查询如何合在一起
  详细解决方案

oracle子查询如何合在一起

热度:92   发布时间:2016-04-24 08:07:35.0
oracle子查询怎么合在一起
本帖最后由 u012293393 于 2014-09-04 16:22:57 编辑
select szzqmc 行政区名称,
       (select count(xzqdm) from ksds where szjg='110000' group by xzqdm) as a,
       (select count(xzqdm) from ksds where szjg='110000' and  zt=1 group by szzqmc)下发数,
       (select count(xzqdm) from ksds where szjg='110000' and  zt=1 and sftb='是' group by szzqmc)应报矿山数,
       (select count(xzqdm) from ksds where szjg='110000' and  sfytb=1 and sftb='是'  group by szzqmc)已报矿山数,
       (select count(xzqdm) from ksds where szjg='110000' and  zt=4 group by szzqmc)已通过审查,
       (select count(k.xzqdm) from ksds k left join scgc s on k.guid = s.guid where szjg='0'and s.kfbszt = 1 and s.clbszt = 1 group by k.szzqmc)已报上级
from ksds
group by szzqmc

(select count(xzqdm) from ksds where szjg='110000' group by xzqdm) as a,这几句都是多行子查询,怎么合在一起?


在线等啊,各位大神。
------解决方案--------------------
首先我很怀疑你原本的语句可以不报错???
你要的应该是:

select szzqmc 行政区名称,
       count(case when szjg='110000' then xzqdm else null end)  a,
       count(case when szjg='110000' and  zt=1 then xzqdm else null end)  下发数,
       count(case when szjg='110000' and  zt=1 and sftb='是' then xzqdm else null end) 应报矿山数,
       count(case when szjg='110000' and  sfytb=1 and sftb='是' then xzqdm else null end) 已报矿山数,
       count(case when szjg='110000'  and  zt=4 then xzqdm else null end)  已通过审查,
       count(case when exists(select 1 from scgc s where s.guid = b.guid and  b.szjg='0'and s.kfbszt = 1 and s.clbszt = 1)                  
           then xzqdm else null ) 已报上级
from ksds  b
group by szzqmc

或者

select szzqmc 行政区名称,
       count(xzqdm )  a,
       count(case when zt=1 then xzqdm else null end)  下发数,
       count(case when zt=1 and sftb='是' then xzqdm else null end) 应报矿山数,
       count(case when sfytb=1 and sftb='是' then xzqdm else null end) 已报矿山数,
       count(case when zt=4 then xzqdm else null end)  已通过审查,
       count(case when exists(select 1 from scgc s where s.guid = b.guid and  b.szjg='0'and s.kfbszt = 1 and s.clbszt = 1)                  
           then xzqdm else null ) 已报上级
from ksds  b
where szjg='110000'
group by szzqmc

注意上面两个是不相等的.
  相关解决方案