select b表.id area_id,SUM(case when status=1 then money else 0 end) count_收入,SUM(case when status=2 then money else 0 end) count_支出,area_name
from a表 join b表 on a表.area=b表.id
group by b表.id,area_name
代码参考如下:
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。
select A from 表名
union
select B from 表名
字段的数据类型必须兼容 同时个数必须相同