2012-08-15 79 views
2

的一部分,我有一個像下面Mysql的COUNT僅按照日期DATETIME

+-----+--------------+---------------------+ 
| id | url   | visit_date   | 
+-----+--------------+---------------------+ 
| 1 + 60   | 2012-06-23 18:15:49 | 
+-----+--------------+---------------------+ 
| 2 + 60&ref=qr | 2012-06-23 12:15:49 | 
+-----+--------------+---------------------+ 
| 3 + 54   | 2012-06-23 18:15:49 | 
+-----+--------------+---------------------+ 
| 4 + 5   | 2012-06-24 18:15:49 | 
+-----+--------------+---------------------+ 
| 5 + 60   | 2012-06-25 13:15:49 | 
+-----+--------------+---------------------+ 
| 6 + 60   | 2012-06-25 19:15:49 | 
+-----+--------------+---------------------+ 

我想組一個表只會導致我的約會。這樣的結果是,如果例如我只想網址60

+-------------+------------------+ 
    |visit_date |count(visit_date) | 
    +-------------+------------------+ 
    | 2012-06-23 |  2   | 
    +-------------+------------------+ 
    | 2012-06-25 |  2   | 
    +-------------+------------------+ 

我曾嘗試以下,但很明顯,我讓每一個日子,由於時間差。

SELECT visit_time, COUNT(visit_time) 
    FROM tracking 
    WHERE query_string LIKE '%60%' 
    GROUP BY visit_time 

只有在忽略時間的日期才能做到這一點嗎?

回答

4

是的,可以。只需使用DATE()函數。

SELECT DATE(visit_time), COUNT(visit_time) 
FROM tracking 
WHERE query_string LIKE CONCAT('%', '60' ,'%') -- makes readable 
GROUP BY DATE(visit_time) 
0

使用此

GROUP BY date(visit_time)