MySQL Average unique x for day of the week
I'm trying to get a MySQL query together to get the average amount of unique devices from a table which logs mac addresses, for each day of the week in a given month and year. So far i have this to count all devices.
SELECT DAYNAME(date_time) dow,
DAYOFWEEK(date_time) day_num,
COUNT( DISTINCT (mac) ) as devices
FROM detected_devices
WHERE client_id = 11
AND venue_id = 1
AND EXTRACT( YEAR FROM date_time) = 2010
AND EXTRACT( MONTH FROM date_time) = 12
GROUP BY dow
ORDER BY day_num
Thats getting me the total number of devices but i can't seem to use the AVG function too. I've tried this line instead but get error #1111 - Invalid use of g开发者_开发问答roup function when i do.
AVG( COUNT( DISTINCT (mac) ) ) as devices
I think this is because you can't GROUP BY
an alias. Try GROUP BY DAYOFWEEK(date_time)
instead.
精彩评论