1.数组准备
create table tbCase1(id int,v1 int,pid int)
create table tbCase2(id int,v1 int)
2.case实验
select *,
case
when 1=1 then 1
else 2
end cat
from tbcase1
3.null 实验
select tc1.id,tc1.v1,tc2.v1,
case tc2.v1
when null then '未连接'
else '已连接'
end cat
from tbcase1 tc1
left join tbcase2 tc2 on tc2.id = tc1.pid
4.isNull函数实验
select tc1.id,tc1.v1,tc2.v1,
case
when ISNULL(tc2.v1) then '未连接'
else '已连接'
end cat
from tbcase1 tc1
left join tbcase2 tc2 on tc2.id = tc1.pid
5.嵌套传参数
select
id
pid,
(select count(*) from tbcase2 where id = pid) as pidCount
from tbcase1