組比較計數我有以下查詢:MySQL的 - 通過
select
DATE_FORMAT(created_at,'%d %M') as day,
count(*) as Total,
count(content_sentiment = 0) as Neutral,
count(content_sentiment < 0) as Negative,
count(content_sentiment > 0) as Positive
from Master
where content_sentiment IS NOT NULL
GROUP BY DAY(created_at)
;
這一點讓我:
day total Neautral Negative Positive
------------------------------------------------------------
01 August 9037 9037 9037 9037
02 August 6439 6439 6439 6439
03 August 5922 5922 5922 5922
04 August 5382 5382 5382 5382
的總價值應該是一個總和的正面,中性和負面的不是即時猜測,因爲每個查詢都會獲得整個表的總數,而不是按天分組。
如何爲每個正面,中性和負面值包含一組?
['COUNT()'](http://dev.mysql.com/doc/refman/5.7/en/group-by-functions .html#function_count)返回「*一個由SELECT語句檢索到的行中的expr的**非NULL **值的數量*」 –
2014-09-05 03:38:51