How can I count how many unique addresses have been on my site each day?
My table looks like this:
Row names: id, name, entity, ip_address, date
1,”Baldur”,”EntityA”,”85.221.18.251″,”2012-01-09 17:32:52″
2,”Baldur”,”EntityB”,”85.221.18.251″,”2012-01-09 17:32:57″
3,”Baldur”,”EntityB”,”85.221.18.252″,”2012-01-09 17:33:01″
4,”Baldur”,”EntityA”,”85.221.18.253″,”2012-01-10 17:33:12″
5,”Mango”,”EntityA”,”85.221.18.257″,”2012-01-10 17:32:52″
6,”Baldur”,”EntityB”,”85.221.18.251″,”2012-01-10 17:32:57″
7,”Mango”,”EntityB”,”85.221.18.253″,”2012-01-11 17:33:01″
8,”Mango”,”EntityA”,”85.221.18.251″,”2012-01-11 17:33:12″
9,”Mango”,”EntityA”,”85.221.18.253″,”2012-01-11 17:32:52″
10,”Baldur”,”EntityB”,”85.221.18.255″,”2012-01-11 17:32:57″
11,”Mango”,”EntityB”,”85.221.18.254″,”2012-01-11 17:33:01″
12,”Mango”,”EntityA”,”85.221.18.251″,”2012-01-12 17:33:12″
I’m thinking something along these lines:
SELECT date, COUNT(ip)
FROM mytable
GROUP BY date
This only gives me rows with count of one.
You are not grouping by a date (meaning one entry per day), but on the actual timestamp, which in your case comes down to a second. You have to apply the
datefunction to extract the actual date from it.On the other hand add the
DISTINCTkeyword to actually count different ips and ignore duplicate entries.