Results 1 to 4 of 4

Thread: HAVING Excersise #3 question/problem/bug?

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    Question 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

  2. #2
    Join Date
    Feb 2013
    Posts
    5
    I agree with u.
    experts, pl help

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    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;

  4. #4
    Join Date
    Feb 2013
    Posts
    5
    Thanks skhanal.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •