Mysql Group by Having

时间:2013-08-06 08:58:11

标签: mysql

我有一张表:

id  ip              count   time                city      country

1   217.165.93.78   1   2013-08-05 02:24:10     DUBAI     UNITED ARAB EMIRATES

2   122.178.229.243 1   2013-08-06 02:25:37     BANGALORE INDIA

3   27.97.27.185    1   2013-08-06 02:26:48     PUNE      INDIA

4   217.165.93.78   1   2013-08-06 02:39:12     DUBAI     UNITED ARAB EMIRATES

我需要根据日期对ip进行分组。

3 个答案:

答案 0 :(得分:0)

我不确定我的问题是否正确,但

怎么样?
select DATE_FORMAT(time, '%d-%m-%Y'), ip 
from testtable
group by DATE(time), ip;

但请提供预期的结果示例

http://sqlfiddle.com/#!2/201ac6/7

答案 1 :(得分:0)

我不确定你到底想要什么。并且你没有显示你希望的结果,然后我想你想要这个

     select `id`, `ip`, count(*) count , `time`, `city`, `country` from table1
     group by ip

DEMO HERE

如果您想按日期查看

   select `id`, `ip`, count(*) count , `time`, `city`, `country` from table1
   where DATE_FORMAT(time, '%Y-%m-%d') = '2013-08-05'
   group by ip

答案 2 :(得分:-2)

尝试使用:group by Convert(varchar(10),time,103)