1
我有這樣的一個表:計數過期未到期及行數爲每個唯一ID
| id | certificate|expires |
| 1 | 123 |12-DEC-15 |
| 1 | 123 |12-DEC-09 |
| 1 | 123 |13-DEC-09 |
| 2 | 456 |14-DEC-16 |
| 2 | 456 |14-DEC-09 |
| 2 | 789 |14-DEC-09 |
| 2 | 789 |14-DEC-09 |
我試圖總結這些過期,未過期一樣爲每個用戶證書的數量這個:
|id | expired | unexpired |
|1 |2 |1 |
|2 |3 |1 |
我已經設法計算所有已過期的證書,但它只顯示沒有過期的行數。如何獲取過期證書的數量?
SELECT
id,
COUNT(certificate) as numcerts,
expires
FROM
certificates
WHERE
expires > current_date()
GROUP BY id
having numcerts > 0
ORDER BY COUNT(*) DESC
你明確地過濾出來的'期滿> CURRENT_DATE()' – zerkms 2015-04-03 10:45:01
使用STR_TO_DATE使文本變成公關操作日期 – Mihai 2015-04-03 10:45:15