CS FundamentalsHardProduct-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, COUNT(*) AS a, COUNT(salary) AS b
FROM Emp
GROUP BY dept
HAVING COUNT(salary) < COUNT(*);
  1. A. No rows
  2. B. NULL, 1, 0 and Sales, 2, 1
  3. C. NULL, 1, 1 and Sales, 2, 1
  4. D. Sales, 2, 1

Correct answer: D. Sales, 2, 1

Only Sales has a NULL salary (Lata): COUNT(*) = 2, COUNT(salary) = 1. The NULL-dept group is Dev, whose salary 45000 is not NULL, so it has 1 and 1 and fails the test.

More DBMS and SQL questions

Exams that ask this topic