with
    t1 as (
        select
            goods_id,
            sum(count) as total
        from
            trans
        group by
            goods_id
        having
            total > 20
    )
	
	
select 
goods.id,
name,
weight,
total
from 
t1
left join 
goods
on t1.goods_id=goods.id
where weight<50
order by goods.id