CS FundamentalsHardGATE CS · Amazon/Microsoft SDE MCQ
Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5, 'Nair', NULL, 200), (6, 'Lata', 'W', 450), (7, 'Mona', 'E', NULL). What values does the second column show for ids 2 and 7? SELECT id, COALESCE(amt, LAG(amt) OVER (ORDER BY id)) FROM Bill;
- A. NULL and NULL
- B. 300 and 450
- C. 300 and NULL
- D. 450 and 450
Correct answer: B. 300 and 450
LAG looks at the previous row by id: for id 2 that is bill 1 (300), and for id 7 it is bill 6 (450). COALESCE takes those because the row's own amt is NULL.
More DBMS and SQL questions
- Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5…
- Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5…
- Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5…
- Table Bill(id, cust, region, amt) rows: (1, 'Kavi', 'E', 300), (2, 'Lata', 'W', NULL), (3, 'Kavi', 'E', 450), (4, 'Mona', 'W', 300), (5…
- R(A, B, C, D, E, F) has functional dependencies AB → C, C → D, D → A, BE → F and F → E. How many candidate keys does R have?
- R(A, B, C, D, E) has functional dependencies A → B, B → C, C → A and D → E. What is the highest normal form R satisfies?