我有一张桌子
| inquiry_id | supplier_id | created |
------------------------------------------------
| 1 | 2 | 2012-10-19 03:10:29 |
------------------------------------------------
| 2 | 2 | 2012-10-17 04:11:23 |
------------------------------------------------
| 3 | 2 | 2012-09-19 03:15:11 |
------------------------------------------------
| 4 | 2 | 2012-09-7 01:16:32 |
------------------------------------------------
我想要一个像mysql一样的结果,
| Month - Year | Total Inquiry |
--------------------------------
| 10-2013 | 2 |
--------------------------------
| 09-2013 | 2 |
--------------------------------
我怎样才能使用MySQL?
答案 0 :(得分:6)
使用DATE_FORMAT()
功能:
SELECT DATE_FORMAT(created,'%m-%Y') AS Month_Year
, COUNT(inquiry_id) AS Total_Inquiry
FROM Table1
GROUP BY DATE_FORMAT(created,'%m-%Y')
答案 1 :(得分:0)
您可以使用:
SELECT DATE_FORMAT(created,'%m-%Y'), COUNT(inquiry_id)
FROM tbl
GROUP BY YEAR(created), MONTH(created)