次のようなテーブルがあります。
ID Customer Name LinkedID
1 A X
2 B Y 1
3 C Z 2
次のクエリを作成する必要があります。
1- For each ID (1,2,3)
2- If there is a LINKEDID defined (2,3 have links)
3- If the CUSTOMER of the LINKEDID is A
4- Return record for that ID
したがって、上記の例では、次のようになります。
- ID の 2、3 には LinkedID が指定されています
- ID2 は顧客 A (良い) リターン ID2 である #1 にリンクします
- ID3 は顧客 B である #2 にリンクします (悪い)
したがって、最終結果は ID2 になります。
SELECT * FROM TABLE WHERE LINKED <> NULL // this will get me the list
? But now how do I iterate over each of the results and compare the customers?
どんな助けでも大歓迎です。ありがとう、