I have a table containing many columns, I have to make my selection according to these two columns:
TIME ID
-216 AZA
215 AZA
56 EA
-55 EA
66 EA
-03 AR
03 OUI
-999 OP
999 OP
04 AR
87 AR
The expected output is
TIME ID
66 EA
03 OUI
87 AR
I need to select the rows with no matches. There are rows which have the same ID, and almost the same time but inversed with a little difference. For example the first row with the TIME -216 matches the second record with time 215. I tried to solve it in many ways, but everytime I find myself lost.
First step — find rows with duplicate IDs. Second step — filter for rows which are near-inverse duplicates.
First step:
The second part of the join clause ensures we only get one record for each pair.
Second step:
This will produce some duplicate results if eg.
(10, FI), (-10, FI) and (11, FI)are in your table as there are two valid pairs. You can possibly filter these out as follows:But it’s unclear which result you want to drop. Hopefully this points you in the right direction, though!