完全外连接 - 来自连接列的交织在一起的值

时间:2012-02-22 00:08:37

标签: sql database postgresql

出于纯粹的教育目的,我应该编写什么而不是*,这样我只能从city_nameweather.city获得一列city.name,无论哪个存在?

flav=# select * from weather full outer join cities on weather.city = cities.name;
     city      | temp_lo | temp_hi | prcp |    date    |     name      | location  
---------------+---------+---------+------+------------+---------------+-----------
 San Francisco |      46 |      50 | 0.25 | 1994-11-27 | San Francisco | (-194,53)
 San Francisco |      43 |      57 |    0 | 1994-11-29 | San Francisco | (-194,53)
 Hayward       |      37 |      54 |      | 1994-11-29 |               | 
               |         |         |      |            | Graz          | (90,-90)

1 个答案:

答案 0 :(得分:2)

找到它:

SELECT COALESCE(city, name) AS city_name ...