CS FundamentalsModerateProduct-company 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). What does this query return?
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).
What does this query return?
SELECT cust FROM Orders GROUP BY cust HAVING COUNT(*) > 1 AND SUM(amount) > 700;
- A. 'Ana' and 'Ben'
- B. Only 'Ana'
- C. Only 'Ben'
- D. No rows
Correct answer: B. Only 'Ana'
Ana has 2 rows with sum 800 (passes). Ben has 2 rows but SUM ignores his NULL, giving 700, which is not > 700. Chen and Dia have one row each. Choosing Ben too treats the condition as ≥ 700 or the NULL as a value.
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'…
- 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, E) has functional dependencies A → BC, CD → E and B → D. Which of the following is a candidate key?
- Account X holds 100. T1 reads X (100); T2 reads X (100); T1 writes X = 150 and commits; T2 writes X = 80 and commits. What is the final…
- Table Orders has a composite B-tree index on (city, amount). Which WHERE clause can use this index to narrow the search most effectively?