I am trying to add up the the numbers from amount, if the booking_id matches. I have been having trouble with summing these numbers as well as adding in a WHERE clause.
This is my code so far
At this time it is summing the numbers correctly, although if I add in the where it doesn't show any results
select *, Sum(amount) FROM payment group by booking_id where booking_id = 1
I have tried some methods like adding queries in queries but I have had no luck. The results I'm attempting to get are below.
booking_id amount
----------------------
1 | 5
2 | 6
1 | 6
3 | 2
3 | 3
4 | 4
Output should be:
booking_id amount
----------------------
1 | 11
2 | 6
3 | 5
4 | 4
I am attempting to group the results so that booking_id with a value of 1 will return a sum of 5+6.
My goal is to be able to add together the amounts that have the same booking id. As well as to be able to include a WHERE clause within this query