Given these two tables:
Table1
id1 | id2 |
---|---|
224 | 2341 |
5234 | 9394 |
6243 | 2342 |
⋮ | ⋮ |
Table2
id | value |
---|---|
224 | 2 |
2341 | 52 |
2342 | 24 |
5234 | 23 |
6243 | 242 |
9394 | 99 |
⋮ | ⋮ |
I would like to create this table:
Table3
id1 | id2 | diff |
---|---|---|
224 | 2341 | 52-2 |
5234 | 9394 | 99-23 |
6243 | 2342 | 24-242 |
⋮ | ⋮ | ⋮ |
where diff
= (value of id2) - (value of id1).
I tried doing this with multiple nested sub-queries with joins, but it seemed quite a belabored/kludgy way of doing it. What is the simplest way of doing this?