Reputation: 15
I join two tables showing different information about a population but in table zp there are some people which are not shown in wg. So I would like to add also these people from zp to the final table, but in the columns where there is no information, I would like to have zeros.
SELECT * FROM mobility.mzmv2010.wegeinland wg
JOIN mobility.mzmv2010.zielpersonen zp USING ("HHNR","ZIELPNR")
An example can be seen in the picture:
Upvotes: 0
Views: 29
Reputation: 1269873
Presumably, you want a left join
. . . with the person table first:
SELECT COALESCE(SUM(zp."WP" * "w_rdist")/(62868 * AVG(zp."WP")), 0)
FROM mobility.mzmv2010.zielpersonen zp LEFT JOIN
mobility.mzmv2010.wegeinland wg
USING ("HHNR", "ZIELPNR") ;
Note: You should qualify the w_rdist
column to specify what table it is coming from.
Upvotes: 1