使用ORDER和GROUP with MySQL来获取每个GROUP的最高编号 [英] Using ORDER and GROUP with MySQL to get the highest number for each GROUP
本文介绍了使用ORDER和GROUP with MySQL来获取每个GROUP的最高编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的网站上做了一个简单的拍卖部分,我想在他们的我的出价页面上显示用户当前的最高出价。我有一张表格,其中包含具有唯一auction_id的每个唯一出价。我目前的查询如下,但这只是排序组而不是排序组内的内容。
I have made a simple auction section on my site, and I would like to display the user's current high bid on their My Bids page. I have a table that holds each unique bid that has the unique auction_id. My current query is as follows, but this only orders the groups instead of ordering what is inside the groups as well. I only want the highest value in each group.
SELECT *
FROM tblAuctionBids
WHERE username = '$username'
GROUP BY auction_id
ORDER BY id DESC
LIMIT 10
推荐答案
SELECT MAX(bid), *
FROM tblAuctionBids
WHERE username='$username'
GROUP BY auction_id
ORDER BY id DESC
LIMIT 10
这篇关于使用ORDER和GROUP with MySQL来获取每个GROUP的最高编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文