如何在mysql的groupby之前进行orderby?

发布于 2024-10-12 10:10:10 字数 347 浏览 5 评论 0原文

我在 mysql order and groupby 找到问题,

但它不起作用,

我得到相同的解决方案:

SELECT * 
FROM (
    SELECT * 
    FROM user 
    ORDER BY create_time DESC
) AS user 
GROUP BY user.role

实现列出每个角色的最新用户

,但mysql的视图不能与subselect一起使用。

I find the question at mysql order and groupby

but it not works,

I get the same solution:

SELECT * 
FROM (
    SELECT * 
    FROM user 
    ORDER BY create_time DESC
) AS user 
GROUP BY user.role

to implement list the newest user of each role

but mysql's view can't work with subselect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝不服输 2024-10-19 10:10:10

Mysql 不支持第一个/最后一个函数

您提供的链接中的答案基于 HAVING 将选择最后一项的面:

SELECT * 
FROM user 
GROUP BY user.role
HAVING  create_time = MAX(create_time)

Mysql doesn't support a first/last function

The answer in the link you provided, is based on the face that HAVING will pick the last item:

SELECT * 
FROM user 
GROUP BY user.role
HAVING  create_time = MAX(create_time)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文