MySQL - select multiple maximum values
I have a table called order
which contains columns id
, user_id
, price
. I would like to select each user's most expensive order - the order for which that user paid the highest price. I want to select order.use开发者_如何学Cr_id
and order.price
in the same query.
select user_id, max(price) from `order` group by user_id
SELECT order.user_id, A.price
FROM `order`
LEFT JOIN
(SELECT user_id, price FROM `order` ORDER BY price DESC) A USING (user_id)
精彩评论