CS FundamentalsHardProduct placement · SQL round
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 counts do Query 1 and Query 2 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 counts do Query 1 and Query 2 return?
-- Query 1 SELECT COUNT(*) FROM (SELECT COUNT(*), SUM(pay) FROM Staff WHERE pay > 100); -- Query 2 SELECT COUNT(*) FROM (SELECT dept, COUNT(*) FROM Staff WHERE pay > 100 GROUP BY dept);
- A. 0 and 1
- B. 0 and 0
- C. 1 and 1
- D. 1 and 0
Correct answer: D. 1 and 0
An aggregate without GROUP BY always returns exactly one row (COUNT 0, SUM NULL) even when no row qualifies. With GROUP BY there are no groups, so no rows.
More DBMS and SQL questions
- R(A, B, C, D, E) with functional dependencies BE → A, C → AD, D → C is decomposed into R1(C, E), R2(A, D, E), R3(A, B, E). Which statement…
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- 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).