I need to complete a SQL Query (Oracle) using a Set Operator, but I am struggling to understand how it would be implemented.
Schema:
Customer (ID, firstN
It's not how you'd normally do this, but as an exercise, you can get the set of all customer IDs, and MINUS the set of all IDs with more than two transactions, which you can get without looking at the customer table a second time:
SELECT C.ID
FROM CUSTOMER C
MINUS
SELECT P.ID
FROM PERFORMS P
INNER JOIN TRANSACTION T
ON T.CODE = P.CODE
GROUP BY P.ID
HAVING COUNT(T.CODE) > 1;
You don't really need to join to TRANSACTION, you can just count the code values in PERFORMS directly:
SELECT C.ID
FROM CUSTOMER C
MINUS
SELECT P.ID
FROM PERFORMS P
GROUP BY P.ID
HAVING COUNT(P.CODE) > 1;
... but maybe there's more to the question what you've shown, like restricting by type or date.