1

I have multiple tables that need to be merged into one.

SELECT name, SUM(money) AS MONEY FROM transactions
JOIN results ON transactions.id = results.id
JOIN more ON results.per_id = more.per_id
GROUP BY name

The output is person's name (first column) and person's money (second column).

name | money
aaron  1220
mike   800
john   200
kate   600

Now I try to filter the result by a money amount, i.e. to show results for people with "Sum(money) > 500"

for that reason I tried putting "WHERE money > 500 GROUP BY name" however the output was wrong (aaron 1000, mike 610, etc..).

how do you write a query to filter the last/ending result?

2 Answers 2

4
Group By Name
having sum(money) > 500

EDIT : what do you meen by "last / ending result" ?

Sign up to request clarification or add additional context in comments.

1 Comment

I've tried to add "GROUP BY name HAVING money > 500" but got an error.. the problem was that I never used SUM ().. to think that the solution was so close. Thank you Raphaël
4

If you want to have the SUM(money) that is greater then 500. Then you can do like this:

SELECT name, SUM(money) AS MONEY FROM transactions
JOIN results ON transactions.id = results.id
JOIN more ON results.per_id = more.per_id
GROUP BY name
HAVING SUM(money)>500

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.