CS FundamentalsHardProduct placement · SQL round
Table Node(id, parent) rows: (1, NULL), (2, 1), (3, 1), (4, 2), (5, 2), (6, 4), (7, 3). What does this query return?
Table Node(id, parent) rows: (1, NULL), (2, 1), (3, 1), (4, 2), (5, 2), (6, 4), (7, 3).
What does this query return?
WITH RECURSIVE sub(id, depth) AS ( SELECT id, 0 FROM Node WHERE id = 2 UNION ALL SELECT n.id, s.depth + 1 FROM Node n JOIN sub s ON n.parent = s.id) SELECT COUNT(*), MAX(depth) FROM sub;
- A. 3, 2
- B. 4, 3
- C. 4, 2
- D. 7, 3
Correct answer: C. 4, 2
Starting at 2 and walking downwards: 2 (depth 0), its children 4 and 5 (depth 1), and 4's child 6 (depth 2). The anchor row is included, so 4 rows.
More DBMS and SQL questions
- R(A, B, C, D, E) has functional dependencies AC → BD, A → CD, C → D, D → A. Which of the following is the complete set of candidate keys…
- Σ = {C → AE, E → B, AE → C, D → C}. Consider the FD AE → C while computing a canonical cover. Which statement about extraneous attributes…
- Which statement about a FOREIGN KEY constraint in standard SQL is correct?
- Table Score(name, pts) rows: ('a', 90), ('b', 85), ('c', 90), ('d', 70), ('e', 85), ('f', 60). What does this query return? sql SELECT…
- Table Staff(id, name, dept, pay, boss) rows: (1, 'Anu', 'Ops', 40, NULL), (2, 'Bala', 'Ops', 55, 1), (3, 'Chitra', 'Tech', 70, 1), (4…
- 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…