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;
- A. 6, 9
- B. 5, 9
- C. 3, 2
- 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
- Fee(sid, fee) has rows (1, 500), (2, 700), (3, 700), (4, 400), (5, 900), (6, 400). What does this return? SELECT SUM(fee) FROM Fee f WHERE…
- Player(pid, team, runs) has rows (1, 'A', 50), (2, 'A', 70), (3, 'A', 70), (4, 'B', 40), (5, 'B', NULL), (6, 'B', 90), (7, 'C', NULL)…
- Cust(cid, city) has rows (1, 'Pune'), (2, 'Delhi'), (3, NULL), (4, 'Pune'). What are the values of Q1: SELECT COUNT() FROM (SELECT city…
- Ord(oid, cid, amt) has no row with cid = 99. What do these return? Q1: SELECT SUM(amt), COUNT() FROM Ord WHERE cid = 99; Q2: SELECT cid…
- R(A, B, C, D, E, F) has functional dependencies AB → C, C → D, D → E, E → A and F → B. How many superkeys does R have?
- R(A, B, C, D, E, F) has functional dependencies A → BC, CD → E, E → A and B → F. It is decomposed into R1(A, B, C, F) and R2(A, C, D, E)…