我的完整问题是我有一个带有customer_id的客户表,带有order_id和order_date和customer_id的订单表,带有order_id和item_id的order_details表以及带有item_id的items表。所以我需要oracle sql查询来获取客户列表放置了最近的购买。谢谢提前
答案 0 :(得分:0)
SELECT cust_id,first_name,last_name FROM customers ORDER BY orderdate DESC;
答案 1 :(得分:0)
好的,让我们做一些基本的假设:
然后,这应该可以解决问题:
SELECT customer_name, most_recent_order
FROM (
SELECT
c.customer_name,
MAX(o.order_date) AS most_recent_order
FROM customers c
JOIN orders o on o.customer_id = c.customer_id
GROUP BY c.customer_name
)
ORDER by most_recent_order desc