Skip to content
Advertisement

SQL Joining of Multiple Tables

SQL newbie here, I am trying to have the table print out the sum of the wages, make, and car model for all the people that own a particular make/model combination. As of right now, the table prints out all the Car Make and Model values, but the SumWage column is all NULL. The SumWage should return the total sum of all the wages of people who have the Make/Model combination.(My select statement is all the way at the bottom of the code)? All advice is much appreciated!

Advertisement

Answer

I think that you want:

This selects all Cars, and follows the relationships towards the Job table, that contains the Wage of each car owner. Data is aggregated by car model and model, and the corresponding wages are sumed.

When a given make/model tuple has no car owner, the sum comes out as null (if you want to just remove these rows from the resultset, use INNER JOINs instead of LEFT JOINs).

Note that you don’t need to bring the Person table to get this resultset.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement