I\'ve been recording the window height of users of my control panel.
I have a table like so:
user_id(INT) | window_height(INT)
--------------------------
To get raw counts
select window_height, count(*) totalusers
from tbl
group by window_height
order by totalusers desc # or by window_height
To get the modal average (this will show multiple values if there are ties for the highest count)
select window_height, totalusers
from (
select @r := if(totalusers>@r,totalusers,@r) maxcount, window_height, totalusers
from (select @r:=0) initvars, (
select window_height, count(*) totalusers
from tbl
group by window_height
) X ) Y
where totalusers = @r
This uses a MySQL trick of using a variable to store the max count as it goes through the aggregated subquery. Summary of operations