-
HAVING Excersise #3 question/problem/bug?
I just got a question, since you say in the #3:
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
-
I agree with u.
experts, pl help
-
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;
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|