34,576
社区成员
发帖
与我相关
我的任务
分享
SELECT ISNULL(a.id,b.number),ISNULL(a.value,0) FROM table1 a RIGHT JOIN(
SELECT number FROM master.dbo.spt_values WHERE [type]='P' AND number in(1,2,3,4)) b
ON a.id=b.number
这个id数据字表你可以自己构建,自带的这个只支持到2047
select id=a.id,
value=isnull(b.value,0)
from (select id=1 union all
select id=2 union all
select id=3 union all
select id=4) a
left join (select *
from table1
where id in(1,2,3,4)) b on a.id=b.id