This is a simple problem, and I'm not sure if its possible here. Here's the problem:
=> http://sqlfiddle.com/#!12/584f1/7
Explanation:
- A ticket belongs to an attendee
- An attendee has a revenue
- I need to group the tickets by section and get the total revenue.
- This double counts attendees because 2 tickets can belong to the same attendee, thus double counting it. I'd like to grab the sum of the revenue, but only count the attendees once.
In my sqlfiddle example, I'd like to see:
section | total_revenue
------------------------
A | 40 <= 40 is correct, but I'm getting 50...
B | null
C | 40
I'd like to solve this without the use of sub queries. I need a scalable solution that will allow me to do this for multiple columns on different joins in a single query. So whatever allows me to accomplish this, I'm open to suggestions.
Thanks for your help.