27,581
社区成员




--给你个例子 有个表#TB1 查询里面记录 如果有显示 记录如果没有显示 0,0,0
create table #tb1(a int,b int,c int)
insert into #tb1 values(1,20,30)
insert into #tb1 values(2,25,32)
insert into #tb1 values(5,15,10)
select * from #tb1 where a=1--第一条有记录显示
union all
select 0,0,0 where not exists (select * from #tb1 where a=1)
union all
select * from #tb1 where a=6--第二条没记录显示0,0,0
union all
select 0,0,0 where not exists (select * from #tb1 where a=6)
--往后以此类推
a b c
----------- ----------- -----------
1 20 30
0 0 0
(2 行受影响)