34,576
社区成员
发帖
与我相关
我的任务
分享
create table #表1
(id int, name char(10) , depart char(10) , att int
)
insert into #表1
select 1 , '张三', 'IT', 1 union all
select 2 , '李四' , 'IT', 2 union all
select 3 , '王五' , 'IT', 1 union all
select 4 , '钱六' , 'IT', 1 union all
select 5 , '王八' , 'IT', 3
create table #表2
(id int, dept char(10) , att int ,moth char(10) ,
)
insert into #表2
select 1 , 'IT', 1 , '2020-05' union all
select 2 , 'IT', 2 , '2020-05'
select * from #表1 left join #表2 on #表1.att= #表2.att and #表2.moth='2020-05'
/*
id name depart att id dept att moth
----------- ---------- ---------- ----------- ----------- ---------- ----------- ----------
1 张三 IT 1 1 IT 1 2020-05
2 李四 IT 2 2 IT 2 2020-05
3 王五 IT 1 1 IT 1 2020-05
4 钱六 IT 1 1 IT 1 2020-05
5 王八 IT 3 NULL NULL NULL NULL
(5 行受影响)
*/