1

I have two tables that I need to gather data from, then add up the sum of one field and return it if the sum is over a certain amount.

Affiliates Table - Table1: [id]
Commissions Table - Table1: [affiliate_id][amount]

I need to grab only affiates where the total commissions 'amount' is over 30.

I will also need to return all of the data from both tables into a single array.

1 Answer 1

1

Try using the HAVING clause.

SELECT affiliate_id, SUM(amount) total_amount 
FROM commissions GROUP BY affiliate_id 
HAVING total_amount > 30
Sign up to request clarification or add additional context in comments.

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.