CS FundamentalsHardProduct-company placement

Using Emp(eid, name, mgr, sal) with rows (1, Kiran, NULL, 100), (2, Lata, 1, 80), (3, Mohan, 1, 120), (4, Neha, 2, 90), (5, Om, 4, 60), (6, Pari, 3, 130), what does this return? WITH RECURSIVE sub(eid, lvl) AS (SELECT eid, 0 FROM Emp WHERE eid = 1 UNION ALL SELECT e.eid, lvl + 1 FROM Emp e JOIN sub ON e.mgr = sub.eid) SELECT COUNT(*), SUM(lvl) FROM sub;

  1. A. 6, 9
  2. B. 5, 9
  3. C. 3, 2
  4. D. 6, 7

Correct answer: A. 6, 9

Levels: Kiran 0; Lata and Mohan 1; Neha and Pari 2; Om (Neha's report) 3. That is 6 rows and 0 + 1 + 1 + 2 + 2 + 3 = 9. The recursion repeats until no new rows appear, so it does not stop at one level (3, 2), and the anchor row is counted.

More DBMS and SQL questions

Exams that ask this topic