I'm attempting to join 3 tables, keeping the data from table 1 and 2, even if the data in table 3 is null. However, when joining the third table it changes the values fetched from table 2 and I cannot, for the life of me, figure out why!
Here's the SQL code that I know works:
select
segment,
count(distinct customers.customer_number) as customers,
round(count(distinct customers) * 100 / sum(count(distinct customers)) over (), 2) as percentage,
sum(amount) as revenue,
round(sum(amount) * 100 / SUM(SUM(amount)) over (), 2) as percentage,
sum(amount) / count(distinct customers.customer_number) as Revenue_Per_Customer
from customers
left join invoices on customers.customer_number=invoices.c_number
group by segment;
This returns the expected values.
However, when I join the third table it will change the values from the second table. The SQL code I add to the above, before the 'group by segment;' line is:
left join support_calls on customers.customer_number=support_calls.c_number
But the result changes the values from the second table.
I just want to add the values from the third table and not have them effect the rest of the table what so ever. Hopefully someone can figure out where I'm going wrong here.