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 3 and 6? SELECT id, SUM(amt) OVER (PARTITION BY cust ORDER BY id ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) FROM Bill;
- A. 750 and NULL
- B. 450 and 450
- C. 300 and 450
- D. 750 and 450
Correct answer: D. 750 and 450
Kavi's partition is ids 1, 3, so id 3 sums 300 + 450 = 750. Lata's partition is ids 2, 6; id 6 sums NULL and 450, and SUM skips the NULL, giving 450.
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…
- 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?
- R(A, B, C, D, E, F, G) has functional dependencies A → B, BC → D, D → E, E → C and F → G. How many candidate keys does R have?