Question discussion

What is the output of the following SQL query?CREATE TABLE emp(id INT, dept TEXT, sal INT); INSERT INTO emp VALUES (1,'A',40),(2,'A',60),(3…

966Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following SQL query?

CREATE TABLE emp(id INT, dept TEXT, sal INT);
INSERT INTO emp VALUES (1,'A',40),(2,'A',60),(3,'B',30),(4,'B',50),(5,'C',70);
SELECT dept, MAX(sal) FROM emp GROUP BY dept
HAVING MAX(sal) >= 60 ORDER BY dept;
  • AA 100, C 70
  • BA 60
  • CA 60, B 50, C 70
  • DA 60, C 70
Correct answer: D

Explanation

Group maxima are A=60, B=50, C=70; HAVING keeps those ≥ 60, i.e. A 60 and C 70.

Discussion 0

Nobody has replied yet. Start the discussion!