1

I have a mysql table,

For simplicity's sake assume the following table was used

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

Is it possible to return a result set for the count of distinct ip addresses in a 24 hour period, every day between now and and 180 days ago?

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
...                    ...
user784637
  • 15,392
  • 32
  • 93
  • 156

2 Answers2

3

try this:

select DATE(`datetime`),count(distinct ipaddress) as ipaddress
from requests
where datediff(NOW(),datetime)<=180
group by DATE(`datetime`)
Joe G Joseph
  • 23,518
  • 5
  • 56
  • 58
0
  select count(Distinct ipaddress  ) as total from 
 requests where date(datetime)> date_sub(date(datetime),interval 2 day)  
 group by ipaddress
Arun Killu
  • 13,581
  • 5
  • 34
  • 61