开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜