I have an MySQL table with fields uid (INT) and TIME (TIMESTAMP) where user logins on the site are registered.
What is the smartiest way to recieve number of users who entered the site during 2 days or more?
Does exists something better then the snippet below which I use?
SELECT count(*) FROM
(SELECT uid, count(*) as DistinctDayCount FROM
(SELECT uid, Time FROM Log GROUP BY uid, DATE(Time)) AS DistinctDays
GROUP BY uid) AS DaysCount
WHERE DistinctDayCount > 1
You can do it with one less subquery:
To be honest, though, I would look at the numbers for each count, using a query such as:
The
minandmaxgive example user ids, which you can investigate further. And often the next question after something like “how many users logged in for more than 1 day” is “what is the distribution of the number of days they logged in”.