SQL: Count values higher than average for a group -
how can 1 use sql count values higher group average?
for example:
i have table a
with:
q t 1 5 1 6 1 2 1 8 2 6 2 4 2 3 2 1
the average group 1 5.25. there 2 values higher 5.25 in group, 8 , 6; count of values higher average group 2.
the average group 2 3.5. there 2 values higher 3.5 in group, 5 , 6; count of values higher average group 2.
try :
select count (*) counthigher,a.q yourtable join (select avg(t) avgt,q yourtable group q) b on a.q=b.q a.t > b.avgt group a.q
in subquery count average value both groups, join on table, , select count of values table value bigger average
Comments
Post a Comment