CS FundamentalsVery hardGATE 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 5 and 1? SELECT id, LAST_VALUE(amt) OVER (ORDER BY amt) FROM Bill WHERE amt IS NOT NULL;
- A. 450 and 450
- B. 200 and 450
- C. 200 and 300
- D. 450 and 300
Correct answer: C. 200 and 300
The default frame ends at the current row and its peers, so LAST_VALUE returns the current row's own peer-group value, not the partition's last: 200 for bill 5 and 300 for bill 1. Getting 450 needs ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING.
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…
- 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?
- R(A, B, C, D) has functional dependencies AB → C, C → D and D → B. Which statement is correct?
- R(A, B, C, D, E) has functional dependencies AB → CD, D → A and C → E. What is the highest normal form R satisfies?