CS FundamentalsHardAmazon/Flipkart SQL round · GATE CS
Table Route(src, dst, cost) rows: ('A', 'B', 5), ('B', 'C', 4), ('A', 'C', 12), ('C', 'D', 3), ('B', 'D', 9), ('D', 'A', 2). What does this query return?
Table Route(src, dst, cost) rows: ('A', 'B', 5), ('B', 'C', 4), ('A', 'C', 12), ('C', 'D', 3), ('B', 'D', 9), ('D', 'A', 2).
What does this query return?
SELECT MIN(r1.cost + r2.cost) FROM Route r1 JOIN Route r2 ON r1.dst = r2.src WHERE r1.src = 'A' AND r2.dst = 'D';
- A. 14
- B. 15
- C. 9
- D. 12
Correct answer: A. 14
Two-leg paths A→?→D: A→B→D costs 5 + 9 = 14 and A→C→D costs 12 + 3 = 15. The cheaper overall route A→B→C→D (12) has three legs and is not produced by this query.
More DBMS and SQL questions
- A file of 1000 blocks is sorted by external merge sort with M = 11 buffer blocks (sorted runs of M blocks are created in pass 0, then (M −…
- The system crashes after the last record of this log (immediate database modification; <Ti, X> denotes an update with old and new values…
- T1 has 3 operations, T2 has 2 and T3 has 2. How many concurrent schedules (interleavings that keep each transaction's own order) exist…
- A query must list departments whose average salary exceeds 50000, considering only employees hired after 2020. Which clause placement is…
- 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) has functional dependencies CE → A, A → CE, BE → A, BC → E, E → BC. What is the highest normal form R satisfies?