# HAVING Excersise #3 question/problem/bug?

• 12-19-2012, 05:55 PM
awesomepeter
HAVING Excersise #3 question/problem/bug?
I just got a question, since you say in the #3:

Quote:

How many orders did each customer make? Use the items_ordered table. Select the customerid, number of orders they made, and the sum of their orders if they purchased more than 1 item.
Exercise #3
and the answer you give is:

Code:

```SELECT customerid, count(customerid), sum(price) FROM items_ordered GROUP BY customerid HAVING count(customerid) > 1;```
but shouldn't it be:

Code:

```SELECT customerid, count(customerid), sum(price) FROM items_ordered GROUP BY customerid HAVING count(quantity) > 1;```
since you say if they purchased more then 1 item, but you count the number of times they ordered not the number of items they bought, don't know if i'm wrong or i found some liddle error :)
• 03-08-2013, 10:52 PM
FutureSQLPro
I agree with u.
experts, pl help
• 03-11-2013, 12:09 PM
skhanal
It does not matter, the count is counting the rows in the grouped rows, it counts 1 for each row, it is not the sum of quantity. So this is good too.

SELECT customerid, count(customerid), sum(price)
FROM items_ordered
GROUP BY customerid
HAVING count(*) > 1;
• 03-11-2013, 03:34 PM
FutureSQLPro
Thanks skhanal.