1

我有一个mysql表,

为简单起见,假设使用了下表

CREATE TABLE requests(
    id INT NOT NULL auto_increment,
    ipaddress VARCHAR(30) NULL,
    datetime DATETIME NULL,
    PRIMARY KEY(id)
);

从现在到 180 天前的每一天,是否可以返回 24 小时内不同 IP 地址计数的结果集?

datetime               ipaddress
2012-10-25 00:00:00    30
2012-10-24 00:00:00    28
2012-10-24 00:00:00    22
2012-10-23 00:00:00    27
...                    ...
4

2 回答 2

3

试试这个:

select DATE(`datetime`),count(distinct ipaddress) as ipaddress
from requests
where datediff(NOW(),datetime)<=180
group by DATE(`datetime`)
于 2012-10-25T06:18:35.003 回答
0
  select count(Distinct ipaddress  ) as total from 
 requests where date(datetime)> date_sub(date(datetime),interval 2 day)  
 group by ipaddress
于 2012-10-25T06:17:33.683 回答