gpt4 book ai didi

sql - MySQL 查询 : work out the average rating for each user then order the results by average rating and number of ratings

转载 作者:行者123 更新时间:2023-11-29 05:00:40 28 4
gpt4 key购买 nike

SELECT username, (SUM(rating)/count(*)) as TheAverage, count(*) as TheCount 
FROM ratings
WHERE month ='Aug' AND TheCount > 1
GROUP BY username
ORDER BY TheAverage DESC, TheCount DESC

我知道这非常接近(我认为),但它表示“TheCount”不存在于 WHERE 子句和 ORDER 子句中。

表格是:

id, username, rating, month

我正在尝试计算每个用户的平均评分,然后按平均评分和评分数量对结果进行排序。

最佳答案

SELECT username, (SUM(rating)/count()) as TheAverage, count() as TheCount 
FROM ratings
WHERE month ='Aug'
GROUP BY username
HAVING TheCount > 1
ORDER BY TheAverage DESC, TheCount DESC

编辑:

看来我看的不够仔细

我认为它现在可以工作了。

关于sql - MySQL 查询 : work out the average rating for each user then order the results by average rating and number of ratings,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1241750/

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