max(),分组依次排列 [英] max(), group by and order by

查看:185
本文介绍了max(),分组依次排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SELECT t.client_id,max(t.points)ASmaxFROM会话GROUP BY t.client_id; 

它只是列出了客户端ID的最大数量。现在我想按max(t.points)排序结果。通常我会使用ORDER BY,但我不知道如何将它用于组。我知道使用SELECT列表中的值在以下子句中是被禁止的,所以在查询结束时添加ORDER BY max将不起作用。



如何在排序后对这些结果进行排序分组,然后呢?



最好的祝愿

解决方案

SELECT t.client_id,max(t.points)ASmax
FROM会话t
GROUP BY t.client_id
按最大值(t.points)排序desc


I have following SQL statement.

    SELECT t.client_id,max(t.points) AS "max" FROM sessions GROUP BY t.client_id;

It simply lists client id's with maximum amount of points they've achieved. Now I want to sort the results by max(t.points). Normally I would use ORDER BY, but I have no idea how to use it with groups. I know using value from SELECT list is prohibited in following clauses, so adding ORDER BY max at the end of query won't work.

How can I sort those results after grouping, then?

Best regards

解决方案

SELECT t.client_id, max(t.points) AS "max" 
FROM sessions t
GROUP BY t.client_id 
order by max(t.points) desc

这篇关于max(),分组依次排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆