2017-06-19 88 views

回答

0

你的陳述包括記錄中有多少人。並且count()計算不是null的一切。所以,你可以在case

count(case when gender='M' then 'hello' end) 

使用比NULL其他任何沒有else部分在case這使得自動null。因此,這是一樣的:

count(case when gender='M' then 'hello' else null end) 

因爲這一切都是相當混亂,我寧願使用sum()代替:

sum(case when gender='M' then 1 else 0 end) 

這並不相同,但國際海事組織是更具可讀性。

在MySQL中,你可以減少到

sum(gender = 'M') 

因爲MySQL中的比較的結果是01,你可以總結這個結果了。

相關問題