如何编写此查询以仅过滤出总和大于50的结果?我无法使用having或sum使其正常工作,但我确定有某种方法。
select name, sum(score)
from submissions inner join hacker on submissions.hacker_id = hacker.hacker_id
group by submissions.hacker_id
order by sum(score) desc
having sum(score) > 50
这里有一个包含表格的示例(表格没有什么特殊之处,此查询在没有最后一行的情况下运行,但会返回所有人的分数和姓名):http://sqlfiddle.com/#!9/7a660d/16
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Order by should be in last
按照应该在最后进行排序
您的order by应该在您的having之后。即:
select name, sum(score) from submissions inner join hacker on submissions.hacker_id = hacker.hacker_id group by submissions.hacker_id having sum(score) > 50 order by sum(score) desc