CS FundamentalsHardGATE CS · SQL
Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2). What does this query return?
Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4, 'Dev', 'Tech', NULL, 3), (5, 'Esha', NULL, 35, 3), (6, 'Farid', 'Tech', 70, 2).
What does this query return?
SELECT SUM(NULLIF(pay, 70)), COUNT(CASE WHEN pay > 50 THEN 1 END) FROM Staff;
- A. 200, 3
- B. 130, 3
- C. 130, 6
- D. 270, 3
Correct answer: B. 130, 3
NULLIF turns both 70s into NULL, so SUM adds 40 + 55 + 35 = 130. A CASE with no ELSE yields NULL for non-matching rows, and COUNT skips NULLs: only Bala, Chitra and Farid count.
More DBMS and SQL questions
- A B+ tree index uses 8192-byte blocks, 24-byte search keys, 10-byte block pointers and 16-byte record (data) pointers. Each leaf also…
- R has 1600 tuples in 80 blocks and S has 20000 tuples in 500 blocks. With only enough memory for one block of each relation, how many…
- Classify the schedule R1(A), W2(B), W1(A), R2(B), W1(B), W2(A), R3(A), W3(B), W3(A).
- Classify the schedule W1(B), W1(A), W3(B), R1(B), R2(B), W3(A), W2(B), R2(A), R3(A).
- Consider the schedule W3(C), W2(A), W1(A), R1(C), R2(A), R2(C), W3(A). Which statement is correct?
- A B+ tree index uses 1024-byte blocks, 10-byte search keys, 6-byte block (tree) pointers and 8-byte record pointers. What is the maximum…