sql - How do I group by using an average? -
i need display names of business has average quantity of less or equal 300.
table s:
busname busnum ------- --------- bob a1 lee a2 ashley a3
table sp:
busnum qty ------- --------- a1 300 a1 400 a1 100 a2 100 a2 100 a2 200 a3 400 a3 300
this i'm trying:
select s.busname s s join sp p on p.busnum = s.busnum group s.busname having avg(p.qty) <= 300;
select busnum
, average of qty
table sp
temporary table, normal join! can do:
select s.busname s, (select busnum, avg(qty) average sp group busnum) temporal s.busnum = temporal.busnum , temporal.average <= 300;
Comments
Post a Comment