2012-04-09 103 views
0

有沒有更好的方法來做到這一點?連續計數非空值

select count(First)+count(id)+count(Last)+count(Telephone) 
from client 
where id ="1"; 
+0

你到底想幹什麼? – theglauber 2012-04-09 19:03:52

+0

獲得一行中非空值的計數 – adayzdone 2012-04-09 19:05:22

+0

我也會對行中空值的計數感到滿意。 – adayzdone 2012-04-09 19:12:36

回答

1

不知道這是更好,但目的可能更清楚後來有人讀它:

select 
    (case when First is null then 1 else 0 end) + 
    (case when id is null then 1 else 0 end) + 
    (case when Last is null then 1 else 0 end) + 
    (case when Telephone is null then 1 else 0 end) 
from client 
where id ="1"; 
+0

這看起來更清潔。我正在尋找一個解決方案,但我並不需要拼出每一列。謝謝。 – adayzdone 2012-04-09 19:11:56

+0

當然 - 不用擔心。我知道如何在tsql中做到這一點;它需要是SQLite嗎? – Geoff 2012-04-09 20:05:24