我能問這樣的:count(a.selected_he =「yes」)是否可以?
having count(a.selected_he = "yes") > 2
我想問如果結果的計數記錄了selected_he = yes
超過2
。 但我不確定我可以在計數功能中寫入a.selected_he = "yes"
。
我對不對?
我能問這樣的:count(a.selected_he =「yes」)是否可以?
having count(a.selected_he = "yes") > 2
我想問如果結果的計數記錄了selected_he = yes
超過2
。 但我不確定我可以在計數功能中寫入a.selected_he = "yes"
。
我對不對?
SELECT sum(CASE WHEN a.selected_he='yes' THEN 1 ELSE 0 END)>2 FROM ...
count
計數非null
S,不true
秒。
'總和'會做的伎倆呢? –
是的,會的。當然你可以「計數(當a.select_he ='yes',然後1 else null結束時)',但你爲什麼要:) –
select id,count(*) as counts
from table
where selected_he = 'yes'
group by id
having counts > 2
如果where子句中的列不包含空值。
假設OP想要過濾掉其餘部分,聽起來像是一個不錯的選擇。但是在這裏沒有很好的定義。 –
你爲什麼不試試自己?諸如「我能做這個還是那個?」的問題如果你真的自己嘗試,通常可以得到更快的回答。 – Griffin
嘗試用sum()代替。比較的布爾結果將被轉換爲一個int(0或1),兩者都將被「計數」。但是,如果你總結(),那麼你只會加上「真」值。 –