sql 怎么将两个查询语句结果连接在一起

2025-03-24 05:48:33
推荐回答(3个)
回答1:

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

回答2:

代码参考如下:
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。

回答3:

select A from 表名
union
select B from 表名
字段的数据类型必须兼容 同时个数必须相同