Sql Server订单最大值

时间:2011-04-11 12:28:11

标签: sql-server

userID  point
111     20 
111     30 
222     40
222     50 

我想点这样订购

222 50  
111 30

DESC的每个userId Max值顺序

3 个答案:

答案 0 :(得分:5)

按MAX点值排序

SELECT userID, MAX(point) 
FROM [table] 
GROUP BY userID 
ORDER BY MAX(point) DESC 

答案 1 :(得分:3)

感谢编辑得很好的问题,我猜你想要这样的东西:

select userID, MAX(point) from tableName
group by userID

并且可选地,也按用户ID排序:

order by userID DESC

答案 2 :(得分:0)

MAX函数仅与SELECT语句相关,因此:

SELECT userID, MAX(point) 
FROM [table] 
GROUP BY userID 
ORDER BY point DESC