0
合併兩個表我有兩個表:MySQL的 - 創建視圖,基於價值觀
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_consolidated表將在除financials_standalone數據。
如:
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 |
我無法找到的情況下,時或左外連接解決方案。如何獲得這個視圖輸出?
謝謝陰影。建議的查詢正在運行。 –