27,580
社区成员
发帖
与我相关
我的任务
分享
------------------------------------
-- Author: happyflystone
-- Version:V1.001
-- Date:2008-09-13 17:44:47
------------------------------------
-- Test Data: tb
If object_id('tb') is not null
Drop table tb
Go
Create table tb(id int,d datetime)
Go
Insert into tb
select 1,'2008-01-01 12:00' union all
select 2,'2008-01-01 12:00'
Go
-- Test Data: ta
If object_id('ta') is not null
Drop table ta
Go
Create table ta(id int,name nvarchar(1))
Go
Insert into ta
select 1,'a' union all
select 2,'b' union all
select 3,'c' union all
select 4,'d' union all
select 5,'e'
Go
--Start
Select a.* ,case when b.d is null then '无打卡记录' else '有打卡记录' end as col
from ta a
left join tb b on a.id = b.id
--Result:
/*
id name col
----------- ---- ----------
1 a 有打卡记录
2 b 有打卡记录
3 c 无打卡记录
4 d 无打卡记录
5 e 无打卡记录
(所影响的行数为 5 行)
*/
--End