如何将三个结果集进行合并显示

finaljia 发布于 2014/03/13 11:14
阅读 147
收藏 0
代码如下:
select sbkjdate,count(1) from sbgreen
where gzdmqsw between '0001' and '3099'
group by sbkjdate


select sbkjdate, count(1) from sbgreen
where gzdmzjlw between '01' and '40' and gzdmqsw between '0001' and '3099'
group by sbkjdate


select sbkjdate,count(1) from sbgreen
where gzdmzjlw between '70' and '99' and gzdmqsw between '0001' and '3099'
group by sbkjdate


这是从一张表中去数据,由于条件不一样不知道如何将这三个结果集进行合并,请高手指点。
加载中
0
gat205
gat205

用union连接

0
f
finaljia
select t1.sbkjdate sbkjdate,num,jx,dq,t4.sbkjnum sbkjnum from (
(select sbkjdate,count(1) num from sbgreen
where gzdmqsw between '0001' and '3099'
group by sbkjdate) t1 join 
(select sbkjdate, count(1) jx from sbgreen
where gzdmzjlw between '01' and '40' and gzdmqsw between '0001' and '3099'
group by sbkjdate) t2 on t1.sbkjdate=t2.sbkjdate join 
(select sbkjdate,count(1) dq from sbgreen
where gzdmzjlw between '70' and '99' and gzdmqsw between '0001' and '3099'
group by sbkjdate) t3 on t1.sbkjdate=t3.sbkjdate join
(select CAST(lx410a as int)+CAST(lx410c as int)+CAST(lxdfm15 as int)+CAST(lxdfm12 as int)
+CAST(lxdfm9 as int)+CAST(lxdfm6 as int)+CAST(lx602 as int)+CAST(lx402 as int)+CAST(lxwr as int)
+CAST(lxdof as int)+CAST(lxcrxf as int)+CAST(slsde as int)+CAST(sltb4 as int)+CAST(slcr as int)
+CAST(hsddx as int)+CAST(hszlj as int)+CAST(hszsrcl as int)+CAST(hsdlj as int)+CAST(hsdlycl as int) sbkjnum,
 sbkjdate from sbkjdetail) t4 on t1.sbkjdate=t4.sbkjdate
) where t1.sbkjdate >= '2014-03-05' and t1.sbkjdate <= '2014-03-09'
order by sbkjdate asc
f
finaljia
已经通过这种方式解决了
返回顶部
顶部