請教一下 如果將in中的結果都顯示出來,不存在則回傳0.
比如:
select * from table1 where id in(1,2,3,4)
實際上資料庫只有2條資料,為id=1,id=2的
如何將結果顯示成
id value
1 value1
2 value2
3 0
4 0
uj5u.com熱心網友回復:
select id=a.id,
value=https://bbs.csdn.net/topics/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
uj5u.com熱心網友回復:
試過了 不行 加了時間 group后 還是只有1條資料 其他的不顯示
uj5u.com熱心網友回復:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/12888.html
標籤:基礎類
上一篇:R語言glm回歸問題
下一篇:電路分析!
