gpt4 book ai didi

MySQL - 选择最近 10 位作者的最新帖子

转载 作者:可可西里 更新时间:2023-11-01 06:33:28 25 4
gpt4 key购买 nike

我有一个表格,其中包含许多不同作者的博客文章。我想做的是显示最近 10 位作者的最新帖子。

每个作者的帖子都按顺序简单地添加到表中,这意味着单个作者可能有多个帖子。我有很多时间想出一个查询来执行此操作。

这给了我最后 10 个唯一的作者 ID;它可以用作子选择来获取每个作者的最新帖子吗?

SELECT DISTINCT userid
FROM posts
ORDER BY postid DESC
LIMIT 10

最佳答案

select userid,postid, win from posts where postid in (
SELECT max(postid) as postid
FROM posts
GROUP BY userid
)
ORDER BY postid desc
limit 10

http://sqlfiddle.com/#!2/09e25/1

关于MySQL - 选择最近 10 位作者的最新帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10181736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com