title: MySQL Average unique x for day of the week
body: <p>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.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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 group function when i do.</p>
  
  <pre><code>AVG( COUNT( DISTINCT (mac) ) ) as devices
  </code></pre>