码迷,mamicode.com
首页 > 数据库 > 详细

mssql查询 两个条件,全满足显示,若没有匹配 局部满足

时间:2020-10-07 21:36:51      阅读:36      评论:0      收藏:0      [点我收藏+]

标签:values   rgb   tab   drop   union   font   select   creat   gif   

技术图片
create table A1(
id int,
classId char(2),
name char(2)
)

insert into A1 values (1,1,A1)
insert into A1 values (1,2,A2)
insert into A1 values (2,2,A3)

create table B1(
id int,
classId char(2),
name char(2)
)

insert into B1 values (1,1,B1)
insert into B1 values (1,2,B2)
insert into B1 values (2,null,B3)



select A1.id Aid,A1.classId AClassId,A1.name A1name,B1.* into #aa from A1 inner join B1 on A1.id = B1.id and A1.classId = B1.classId

select * from #aa
union
select * from A1 inner join B1 on A1.id = B1.id and not exists(select * from #aa a where A1.id =a.Aid and A1.classId = a.AClassId )
    
drop table #aa
drop table A1
drop table B1
View Code

 

mssql查询 两个条件,全满足显示,若没有匹配 局部满足

标签:values   rgb   tab   drop   union   font   select   creat   gif   

原文地址:https://www.cnblogs.com/DannyK/p/13777814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!