0

I'm trying to figure out how create a MySQL SELECT statement that will select users from one table, get the SUM of their payments in another table for each user, and set a conditional statement on that SUM. Something like this:

SELECT member_id
FROM users_table
WHERE SUM(payments) FROM payments_table > 100;

Any help would be greatly appreciated.

1 Answer 1

2

something like

select member_id from payments_table 
group by member_id 
having sum(payments) > 100 

or

select u.member_id, u.name 
from payments_table p 
join users_table u
on p.member_id = u.member_id
group by u.member_id, u.name 
having sum(p.payments) > 100 
Sign up to request clarification or add additional context in comments.

1 Comment

i guess this query will work fine because member_id is a foreign key in the payment table .. is that the case ?

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.