CS FundamentalsHardTCS NQT · Infosys interview pattern
Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen', 'Delhi', 700), (5, 'Dia', NULL, 200), (6, 'Ben', 'Delhi', 700). For the order with id 1, what are the values of r and dr?
Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen', 'Delhi', 700), (5, 'Dia', NULL, 200), (6, 'Ben', 'Delhi', 700).
For the order with id 1, what are the values of r and dr?
SELECT id,
RANK() OVER (ORDER BY amount DESC) AS r,
DENSE_RANK() OVER (ORDER BY amount DESC) AS dr
FROM Orders WHERE amount IS NOT NULL;- A. r = 2, dr = 2
- B. r = 3, dr = 3
- C. r = 3, dr = 2
- D. r = 2, dr = 3
Correct answer: C. r = 3, dr = 2
Amounts in order: 700, 700, 500, … The two 700s share rank 1. RANK leaves a gap, so 500 gets rank 3; DENSE_RANK does not, so 500 gets 2. ROW_NUMBER would give 3 as well, but without ties.
More DBMS and SQL questions
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- R(A, B, C, D) has FDs A → B and C → D. It is decomposed into R1(A, B), R2(C, D) and R3(A, C). Which statement is correct?
- R(A, B, C, D) has exactly two candidate keys: A and BC. How many superkeys does R have?
- You need the customers who have placed no orders. Orders.cust may contain NULL values. Which query is correct in that case?
- Table Proj(pid, lead, dept, budget, parent) rows: (1, 'Uma', 'R&D', 900, NULL), (2, 'Vik', 'R&D', 400, 1), (3, 'Uma', 'Ops', NULL, 1), (4…