两个SQL查询,横向合并为一个查询结果教程
第一条sql:
select unit,count(*)as number from archives\_management group by unit
第二条sql:
select fine\_units,count(*) as fine\_number from fine group by fine\_units
注:两条sql 分别查询结果如下图
要求生成如下格式:
unit number fine\_number
艾XXXXXXX 1 1
奥XXXXXXXX 1 0
北京XXXXXXX 2 0
解决办法:
select isnull(a.unit,b.fine\_units) unit,isnull(a.number,0) number,isnull(b.fine\_number,0) fine\_number
from (第一个SQL) a FULL JOIN (第二个SQL) b on a.unit=b.fine\_units