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 does this query return? SELECT SUM(CASE WHEN amt > 300 THEN 1 WHEN amt <= 300 THEN 0 ELSE -1 END) FROM Bill;
- A. 5
- B. -2
- C. 0
- D. NULL
Correct answer: C. 0
Bills 3 and 6 give 1 each, bills 1, 4 and 5 give 0, and for the two NULL amounts both comparisons are UNKNOWN, so CASE falls to ELSE -1. Total 2 + 0 - 2 = 0; CASE never returns NULL here.
More DBMS and SQL questions
- 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?
- R(A, B, C, D, E) has functional dependencies A → BC, CD → E, B → D and E → A. What are all the candidate keys of R?