Comparing the average in MYSQL -


if have table

shirt  +--------+------+ | color  | size | +--------+------+ | red    |    2 | | red    |    4 | | red    |    2 | | blue   |    3 | | blue   |    5 | | yellow |    2 | | yellow |    7 | +--------+------+ 

and want display ones above average

so

shirt   +--------+------+ | color  | size | +--------+------+ | red    |    4 | | blue   |    5 | | yellow |    7 | +--------+------+ 

what best way in mysql?

edit: have code different set made quick example can see how it's done try myself.

try:

select shirt.color, shirt.size shirt inner join (select color, avg(size) size shirt group color) table2 on shirt.color = table2.color shirt.size >= table2.size 

here's sqlfiddle

update

with same table name.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -