sqlserver中将两个SQL语句查询出来的值合并
有两个语句:
select DeptName,COUNT(*) as ⼊院⼈数 from I_PatientRegist where TypeState=0 group by DeptName
select DeptName,COUNT(*) as 肺炎⼈数 from I_PatientRegist where InIcdName like '%肺炎%' group by DeptName
sql语句查询结果取反查询结果如下:
⽬标结果是:
答案如下:
select a.DeptName,isnull(a.⼊院⼈数,0) ⼊院⼈数,isnull(b.肺炎⼈数,0) 肺炎⼈数
from
(select DeptName,COUNT(*) as ⼊院⼈数 from I_PatientRegist where TypeState=0 group by DeptName)
A FULL JOIN
(select DeptName,COUNT(*) as 肺炎⼈数 from I_PatientRegist where InIcdName like '%肺炎%' group by DeptName) b on a.DeptName=b.DeptName
语法如下:
select 字段列表 from (第⼀个SQL语句) A FULL JOIN (第⼆个SQL语句) b on a.字段=b.字段
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论