How to use sum function to filter window functions in MYSQL
P粉186904731
2023-08-30 22:03:52
<p>How can I write this query to filter out only results with a sum greater than 50? I can't get it to work using having or sum, but I'm sure there is some way. </p>
<pre class="brush:php;toolbar:false;">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</pre>
<p>Here is an example with a table (there is nothing special about the table, this query runs without the last row, but returns everyone's score and name): http://sqlfiddle.com/# !9/7a660d/16</p>
Order by should be in last
Sort according to what should be at the end
Your order by should be after your having. Right now: