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
Post a Comment