Evaluating a query with WHERE and HAVING

An online shop records orders in a table called orders, with each amount in dollars:


order_id

customer

amount

1

Lee

40

2

Kim

125

3

Lee

60

4

Ortiz

15

5

Kim

30

6

Patel

210

7

Ortiz

90

8

Lee

20

9

Patel

5


The shop runs this query:


SQL
SELECT customer, SUM(amount) AS total
FROM orders
WHERE amount >= 20
GROUP BY customer
HAVING SUM(amount) > 100;


Give the number of rows the query returns, the total reported for Patel in dollars and the total reported for Lee in dollars, each as a whole number.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Declarative Languages Questions: