Sql中多种结果集合并
Posted 最小的帆也能远航
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sql中多种结果集合并相关的知识,希望对你有一定的参考价值。
--部门发文数
select so.fd_name,count(ks.fd_id) as data_value
from km_imissive_send_main ks,sys_org_element so
where ks.fd_sendplan_dept_id =so.fd_id
and fd_is_controller=1
and ks.fd_is_numbered=1
and year(ks.doc_create_time)=year(now())
and so.fd_org_type=2
group by so.fd_name
--初始值
select so.fd_name,sum(kp.fd_num) as data_value
from km_imissive_planp kp,sys_org_element so
where kp.fd_dept_Id=so.fd_id
and kp.fd_is_available=1
and kp.fd_plan_yeat=year(now())
group by so.fd_name
多种结果集通过union all合并
select temp.fd_name,sum(temp.data_value)from(
select so.fd_name,count(ks.fd_id) as data_value
from km_imissive_send_main ks,sys_org_element so
where ks.fd_sendplan_dept_id =so.fd_id
and fd_is_controller=1
and ks.fd_is_numbered=1
and year(ks.doc_create_time)=year(now())
and so.fd_org_type=2
group by so.fd_name
union all
select so.fd_name,sum(kp.fd_num) as data_value
from km_imissive_planp kp,sys_org_element so
where kp.fd_dept_Id=so.fd_id
and kp.fd_is_available=1
and kp.fd_plan_yeat=year(now())
group by so.fd_name) temp
group by temp.fd_name
以上是关于Sql中多种结果集合并的主要内容,如果未能解决你的问题,请参考以下文章