Question discussion

What is the output of the following SQL query?CREATE TABLE emp(id INT, dept INT, sal INT); INSERT INTO emp VALUES (1,10,50),(2,10,70),(3,20…

1556Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following SQL query?

CREATE TABLE emp(id INT, dept INT, sal INT);
INSERT INTO emp VALUES (1,10,50),(2,10,70),(3,20,40),(4,20,40),(5,20,90);
SELECT id FROM emp e WHERE sal >
(SELECT AVG(sal) FROM emp WHERE dept = e.dept) ORDER BY id;
  • A2, 5
  • B1, 3, 4
  • C2, 3, 4, 5
  • D2
Correct answer: A

Explanation

The department averages are 60 (dept 10) and about 56.7 (dept 20), so only employee 2 (70) and employee 5 (90) earn more than their own department's average.

Discussion 0

Nobody has replied yet. Start the discussion!