table_customers(customer_id, customer_name)
table_orders(customer_id, order_id, order_datetime)
我想要獲得last order date
每個customer
。如果客戶沒有爲她訂購任何退貨00-00-0000
。如何在mysql中選擇每個客戶的最後訂單日期
這是我的查詢。
select C.customer_id , date(O.order_datetime)
from table_customers C
INNER JOIN table_orders O ON C.customer_id = O.customer_id
group by O.customer_id order by O.order_datetime desc limit 1;
它僅爲最後一位客戶返回最後一個訂單日期。
如何獲取所有客戶的最後訂單日期?
刪除'limit 1'? – David