2

我有一张如下表

 +-----+--------------+---------------------+
 | 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 的 url。

  +-------------+------------------+
  |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

2 回答 2

4

是的你可以。只需使用DATE()功能。

SELECT DATE(visit_time), COUNT( visit_time ) 
FROM tracking
WHERE query_string LIKE  CONCAT('%', '60' ,'%')  -- makes readable
GROUP BY DATE(visit_time)
于 2012-08-15T03:09:13.943 回答
0

用这个

GROUP BY date(visit_time)
于 2012-08-15T03:09:09.390 回答