SQL 同一张表俩条查询相同字段的语句不同结果合并成一条语句,输出所有字段信息

2025-01-19 16:10:40
推荐回答(2个)
回答1:

select A0190 as '工号', A0101 as '姓名',C2108 AS '应发',C211H AS '实发'from C21 where gz_ym = '201904' and a0188 not in (select a0188 from C21 where gz_ym= dbo.ym_s('201904') and a0191 not in ('黑名单','外包工'))and a0191 not in ('黑名单','外包工') union all
select A0190 as '工号', A0101 as '姓名',C2108 AS '应发',C211H AS '实发'from C21 where gz_ym= dbo.ym_s('201904') and a0188 not in (select a0188 from C21 where gz_ym = '201904' and a0191 not in ('黑名单','外包工'))and a0191 not in ('黑名单','外包工')

回答2:

最简单的办法是两条sql语句之间用【union】连接
或者是where条件用【or】来连接