gpt4 book ai didi

mysql - 热门评论、热门用户、热门用户和评论 mysql

转载 作者:行者123 更新时间:2023-11-29 14:54:10 24 4
gpt4 key购买 nike

我有 2 个表评论 | 投票

The `votes` structure is:
[`id` | `user_id` | `comment_id` | `rating`]

并且评论以comment_id为主。现在我想根据评分总和获得最高评论。

[评分为 0 或 1]

我也想获得顶级用户。

最佳答案

这将返回前 10 条评论,或多或少地更改限制。显然将 * 替换为您想要从评论中返回的列

select *
from comments x
join (select comment_id, sum(rating)
from votes
group by comment_id
order by sum(rating) desc
limit 10 ) z on x.comment_id = z.comment_id

用户将以同样的方式完成,只需更改 user_id 中的 comment_id 并加入到您

关于mysql - 热门评论、热门用户、热门用户和评论 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5064521/

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