I have got a problem with a MySQL SQL-command.
I have got a table with 3 columns:
id (int) | ip(string) | time(mysql timestamp)
I want to have a count with all rows grouped by time. I use the following code for it:
SELECT DATE( TIME ) as date, COUNT( * ) as count
FROM table
WHERE TIME > ( NOW( ) - INTERVAL 10 DAY )
GROUP BY DATE( `time` )
Well, but now, I want to ignore double IPs. For example:
If i have put the following datas in the mysql table:
ID | time | IP
--------------------------------------
1 | 2013-01-21 20:48:01 | 127.0.0.1
2 | 2013-01-22 20:48:01 | 127.0.0.1
3 | 2013-01-22 20:48:01 | 127.0.0.1
4 | 2013-01-22 20:48:01 | 127.0.0.3
I want only see the following datas:
date | count
------------------
2013-01-21 | 1
2013-01-22 | 2
What is the best way to do it? I’m not going to create in my application a loop which remove all duplicates because the table grows quickly and I will cost much resources if I do it in my application.
Try this:
SQL FIDDLE DEMO