题解 | 商品交易(网易校招笔试真题)
商品交易(网易校招笔试真题)
https://www.nowcoder.com/practice/f257dfc1b55e42e19eec004aa3cb4174
select a.id,a.name,a.weight,sum(count) as total from (select * from goods where weight<50) a join trans b on a.id=b.goods_id group by a.id,a.name,a.weight having sum(count)>20 order by a.id
多表连接前,先把题目所需的数据筛出来,避免连接再筛。
查找购买个数超过20,质量小于50的商品。
先把质量小于50的数据筛出来,内连接,不是质量小于50的订单数据全部剔除,然后再分组,条件筛选,排序。