QUERY: SELECT domain,distinct count (ip) as count FROM `stat` WHERE `time`='2009-12-6' group by `domain` I want to get list of records grouped by domains and in those records count number of records with unique ip address.
distinct is a field in your table? you can't use disctint as a field or table name. it's a reserve word..
Following might help.. SELECT domain, COUNT (DISTINCT ip) AS DomainCount FROM `stat` WHERE `time`='2009-12-6' GROUP BY `domain` I hope time column's data type is date otherwise query will not yield anything. Let us know table structure and the report you wish with example and we will help you build query.
What records do you want to show? BTW Why are you using count() for the ip value? Why would you want to return the number of ips per domain? Maybe I don't understand and distinct and group by are always fun to play with lol. Hopefully you get it.