CS FundamentalsModerateProduct-company MCQ pattern

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). What does this query return?

Table Emp(id, name, dept, salary, mgr) rows: (1, 'Asha', 'HR', 50000, NULL), (2, 'Ravi', 'IT', 70000, 1), (3, 'Meena', 'IT', 70000, 2), (4, 'John', 'Sales', 40000, 1), (5, 'Kiran', 'IT', 90000, 2), (6, 'Dev', NULL, 45000, 4), (7, 'Lata', 'Sales', NULL, 4). What does this query return?
SELECT dept FROM Emp
GROUP BY dept
HAVING AVG(salary) > 50000;
  1. A. IT
  2. B. IT and Sales
  3. C. IT and HR
  4. D. IT, HR and Sales

Correct answer: A. IT

Averages: HR 50000 (not > 50000), IT (70000 + 70000 + 90000)/3 ≈ 76667, Sales 40000 (Lata's NULL is ignored by AVG, not counted as 0), NULL group 45000. Only IT qualifies.

More DBMS and SQL questions

Exams that ask this topic