我有两个源视图:
View1
-----------------------------------------------------
| UserId | RoleId | Total1 (calculated value) |
-----------------------------------------------------
| 1 | 21 | 9 |
-----------------------------------------------------
| 1 | 22 | 5 |
-----------------------------------------------------
| 2 | 21 | 7 |
-----------------------------------------------------
| 4 | 23 | 4 |
-----------------------------------------------------
View2
-----------------------------------------------------
| UserId | RoleId | Total2 (calculated value) |
-----------------------------------------------------
| 1 | 21 | 2 |
-----------------------------------------------------
| 1 | 24 | 1 |
-----------------------------------------------------
| 3 | 21 | 3 |
-----------------------------------------------------
| 4 | 21 | 4 |
-----------------------------------------------------
首选输出基于 UserId AND RoleId 相等性:
---------------------------------------------
| UserId | RoleId | Total1 | Total2 |
---------------------------------------------
| 1 | 21 | 9 | 2 |
---------------------------------------------
| 1 | 22 | 5 | NULL |
---------------------------------------------
| 1 | 24 | NULL | 1 |
---------------------------------------------
| 2 | 21 | 7 | NULL |
---------------------------------------------
| 3 | 21 | NULL | 3 |
---------------------------------------------
| ... | ... | ... | ... |
据我所知,我应该使用某种类型的 OUTER JOIN - 但是如何?