CS FundamentalsHardAccenture · Capgemini technical pattern
Which of these queries is NOT valid in standard SQL?
- A. SELECT cust, amount FROM Orders GROUP BY cust;
- B. SELECT cust, SUM(amount) FROM Orders GROUP BY cust;
- C. SELECT cust FROM Orders GROUP BY cust HAVING MAX(amount) > 300;
- D. SELECT COUNT(*) FROM Orders;
Correct answer: A. SELECT cust, amount FROM Orders GROUP BY cust;
With GROUP BY, every selected column must be grouped or aggregated; amount is neither, and a group like Ana has two different amounts. (MySQL’s loose mode may accept it and pick an arbitrary value, but it is invalid in standard SQL.)
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'…
- 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) has FDs A → B and C → D. It is decomposed into R1(A, B), R2(C, D) and R3(A, C). Which statement is correct?
- R(A, B, C, D) has exactly two candidate keys: A and BC. How many superkeys does R have?