假设以下示例表:
+-----+-----+-----+
| ID1 | ID2 | VAL |
+-----+-----+-----+
| A | X | 1 |
| A | Y | 2 |
| A | Z | 3 |
| B | X | 4 |
| B | Z | 5 |
| C | Y | 6 |
+-----+-----+-----+
说我感兴趣ID1 = B
并想与其他人进行比较。所需的输出将是:
+---------+---------+---------+---------+---------+---------+---------+
| REF.ID1 | OTH.ID1 | REF.ID2 | REF.ID2 | REF.VAL | OTH.VAL | DIFF |
+---------+---------+---------+---------+---------+---------+---------+
| B | A | X | X | 4 | 1 | 3 |
| B | A | NULL | Y | NULL | 2 | -2 |
| B | A | Z | Z | 5 | 3 | 2 |
| B | B | X | X | 4 | 4 | 0 |
| B | B | Z | Z | 5 | 5 | 0 |
| B | C | NULL | Y | NULL | 6 | -6 |
+---------+---------+---------+---------+---------+---------+---------+
谢谢你。