我有两张桌子:
financials_standalone ('fin_id', 'attr_id', 'year', 'value');
financials_consolidated ('fin_id', 'attr_id', 'year', 'value');
('fin_id', 'attr_id', 'year') is the unique key
除了financials_standalone 之外,financials_consolidated 表还有数据。
例如:
financials_standalone
| fin_id | attr_id | year | value |
---------------------------------------
| fin01 | pe | 2016 | 33.23 |
| fin02 | pe | 2016 | 12.52 |
financials_consolidated
| fin_id | attr_id | year | value |
---------------------------------------
| fin02 | pe | 2016 | 20.41 |
现在我想将这两个表合并为一个视图:- 如果该行存在于合并中,则选择该行,否则从 Financials_standalone 表中选择该行。
所以最终的视图输出应该是这样的
financials_data_view
| fin_id | attr_id | year | value |
---------------------------------------
| fin01 | pe | 2016 | 33.23 |
| fin02 | pe | 2016 | 20.41 |
我无法通过 case-when 或 left external join 找到解决方案。如何获得此视图输出?