select
    goods.id as id,
    name,
    weight,
    sum(trans.count) as total

from
    trans left join goods on trans.goods_id=goods.id
where
    weight<50
group by
    goods_id
having
    total>20
order by
    id