#第一步: 两表合并,合并待处理的数据

#第二步:按照商品id汇总数量,注意distinct去重

#第三步:根据步骤二的表,按照题目要求提取数据即可

SELECT g.id, g.name, g.weight, t.count FROM goods g LEFT JOIN trans t ON g.id = t.goods_id
#第二步:按照商品id汇总数量,注意distinct去重
SELECT DISTINCT id,NAME,weight, SUM(COUNT) over(PARTITION BY id) "total" FROM (SELECT g.id, g.name, g.weight, t.count FROM goods g LEFT JOIN trans t ON g.id = t.goods_id) f
#第三步:根据步骤二的表,按照题目要求提取数据即可
SELECT id, NAME, weight, total FROM (SELECT DISTINCT id,NAME,weight, SUM(COUNT) over(PARTITION BY id) "total" FROM (SELECT g.id, g.name, g.weight, t.count FROM goods g LEFT JOIN trans t ON g.id = t.goods_id) f) ff WHERE weight < 50 AND total > 20 ORDER BY id