题目链接:点击打开链接
题目大意:略。
解题思路:略。
AC 代码
-- 解决方案(1) WITH t AS(SELECT order_id, order_date, product_id, DENSE_RANK() OVER(PARTITION BY product_id ORDER BY order_date DESC) rk FROM Orders) SELECT product_name, t.product_id, order_id, order_date FROM t JOIN Products USING(product_id) WHERE rk = 1 ORDER BY product_name, t.product_id, order_id -- 解决方案(2) select product_name, o.product_id, order_id, order_date from Orders o left join Products p using(product_id) where (product_id, order_date) in ( select product_id, max(order_date) order_date from Orders group by product_id ) order by product_name, product_id, order_id