[thelist] RE: (SQL) Count Distincts

Sherzod Ruzmetov mysql at handalak.com
Sat Feb 1 00:03:00 CST 2003


    :
    : I am trying to get a count of Distinct IP's from my homemade hit-log
    : database (don't ask).  The db is MySQL.  I'm trying this:
    :
    : SELECT DISTINCT ClientIP, COUNT(*), Month(TimeStamp),
    : DayOfMonth(TimeStamp) FROM RedirectLog WHERE (TimeStamp BETWEEN
    : '20030130000000' AND '20030131000000') GROUP BY Month(TimeStamp),
    : DayOfMonth(TimeStamp)


Looks like you are working on a project similar to
http://traffic.handalak.com
(login: demo password: demo).

In the above example, you're trying to retrieve how many times a unique user
(arguably) visited a site on certain month? In that case, you need to drop
distinct
and group it by IP address and specify the date inside WHERE clause.
Simplified version
would look something like:

 SELECT ClientIP, COUNT(*)
	FROM redirectLog
		WHERE MONTH(timeStamp) = MONTH(CURDATE())
			GROUP BY clientIP;


Good luck

Sherzod





More information about the thelist mailing list