# 先作质量筛选
select *
from goods
where weight < 50

# 连接goods表和trans表再作购买数目的筛选
select goods_id id, name, weight, sum(count) total
from (
    select *
    from goods
    where weight < 50
) t1
join trans t
on t1.id = t.goods_id
group by goods_id
having sum(count) > 20
order by id;