我有一个mysql表,
为简单起见,假设使用了下表
CREATE TABLE requests(
id INT NOT NULL auto_increment,
ipaddress VARCHAR(30) NULL,
datetime DATETIME NULL,
PRIMARY KEY(id)
);
是否可以在24小时内,从现在到180天之前的每一天返回不同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
... ...
答案 0 :(得分:3)
试试这个:
select DATE(`datetime`),count(distinct ipaddress) as ipaddress
from requests
where datediff(NOW(),datetime)<=180
group by DATE(`datetime`)
答案 1 :(得分:0)
select count(Distinct ipaddress ) as total from
requests where date(datetime)> date_sub(date(datetime),interval 2 day)
group by ipaddress