商品表(goods)商品id、商品名name、商品质量 weight
交易表(trans), 交易id、商品id goods_id、这个商品购买个数count
条件:
购买个数超过20,质量小于50的商品,按照商品id升序排序
能写在where里的,尽量不要用having。
select g.id, g.name, g.weight, sum(t.count) total
from goods g, trans t
where g.id = t.goods_id
and g.weight < 50
group by g.id
having sum(t.count) > 20
order by g.id 已知数据: