第一条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 分别查询结果如下图

两个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

原文引用:https://bbs.csdn.net/topics/390797414?page=1

标签: 查询, number, select, SQL, units, unit, isnull, 横向, fine

相关文章推荐

添加新评论,含*的栏目为必填