题解 | #商品交易(网易校招笔试真题)#
商品交易(网易校招笔试真题)
http://www.nowcoder.com/practice/f257dfc1b55e42e19eec004aa3cb4174
知识点
- 首先把两个表连接,使用group by进行分组各类返回一行。
- 筛选条件使用having进行筛选最后对id进行排序。
代码
select g.id, name, weight, sum(count) as total
from trans as t
join goods as g
on t.goods_id = g.id
group by g.id
having total> 20 and weight < 50
order by g.id