(ORACLE SQL) about subquery and operators like ALL,ANY etc

210 Views Asked by At

I have 3 Tables

CREATE TABLE airships( 
    idas number PRIMARY KEY, 
    nameas varchar2(20), 
    range number 
);

CREATE TABLE Certificate( 
    idem number NOT NULL, 
    idas number NOT NULL, 
    FOREIGN KEY (idem) REFERENCES employees(idem), 
    FOREIGN KEY (idas) REFERENCES airships(idas) 
);

CREATE TABLE employees( 
    idem number PRIMARY KEY, 
    nameem varchar2(20), paycheck number 
);

I have to find idem for those employees who are certified for the biggest number of airships using a subquery and oparatos like EXISTS,IN,ALL,ANY

I've managed to find only one employee, whithout usig any of the oparatos.

Select  *
from (Select idem,count(idas) as AirshipName
      From Certificate
      Group By idem
      Order By count(idas) DESC)
WHERE ROWNUM=1
1

There are 1 best solutions below

5
On

I'm not sure how to do it using the specific operators you list. Here's how to do it with HAVING

The ALL operator is explained here. You can use this query:

SELECT "idem"
FROM Certificate
GROUP BY "idem"
HAVING COUNT(*) >= ALL (
    SELECT COUNT(*)
    FROM Certificate
    GROUP BY "idem")

DEMO