Table users : id (int) status (int) regdate (datetime)
我想要得到的結果regdate的順序,數量(ID)的和組的狀態。Mysql查詢與羣組?
例如:
Date Count(status = 3) Count(status = 4) Count(status = 5)
2014-02-24 2 5 8 2014-02-25 2 5 8
我們要有獲得每天只一行的結果。
預先感謝太多。
Table users : id (int) status (int) regdate (datetime)
我想要得到的結果regdate的順序,數量(ID)的和組的狀態。Mysql查詢與羣組?
例如:
Date Count(status = 3) Count(status = 4) Count(status = 5)
2014-02-24 2 5 8 2014-02-25 2 5 8
我們要有獲得每天只一行的結果。
預先感謝太多。
可以使用SUM()
與條件,如果有法規限制像3,4,5,在SUM()的表達被評估爲布爾值,對於n個沒有。的法令看看Marc B的意見
SELECT
regdate,
SUM(status = 3),
SUM(status = 4),
SUM(status = 5)
FROM `table`
GROUP BY regdate
ORDER BY regdate
這就是所謂的數據透視查詢,而且mysql不直接支持它們。該解決方法很難看,並且非常快速地得到極其不可維護性。正常提取查詢並在客戶端代碼中進行col-> row轉換。 –