Question discussion

What is the output of the following SQL statements?CREATE TABLE orders(cust TEXT, amt INT); INSERT INTO orders VALUES ('a',100),('b',250),(…

1778Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following SQL statements?

CREATE TABLE orders(cust TEXT, amt INT);
INSERT INTO orders VALUES ('a',100),('b',250),('a',300),('c',50),('b',150),('a',200);
SELECT cust, SUM(amt) FROM orders GROUP BY cust HAVING COUNT(*) >= 2 ORDER BY cust;
  • Aa 600, b 400, c 50
  • Ba 600, b 400
  • Ca 3, b 2
  • Da 600, c 50
Correct answer: B

Explanation

Customers a (3 orders, total 600) and b (2 orders, total 400) pass the HAVING condition, whereas c has only one order.

Discussion 0

Nobody has replied yet. Start the discussion!