Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2007
    Posts
    12

    Unanswered: Using SubQuery to Count 0 Sales Stores

    I am trying to learn subquery and I can't wrap my head around this one and hoping someone can show me.

    Say table [tbl_Info] has these fields:
    1. Week
    2. Item
    3. Store Number
    4. Sales

    How should I write a subquery to count the number of stores the have 0 sales for each particular item?
    Last edited by lazyme; 06-13-11 at 17:17.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    You haven't posted enough information to answer that question. Please post the whole assignment so we can see what the intructor is trying to teach and the other information needed to solve this problem.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Oct 2007
    Posts
    12
    PatP, thanks for your reply. Do you understand the question? What else do you need to answer to suggest a solution?

    Side note, I am the instructor teaching myself SQL.

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    You have to determine all stores and subtract all stores that do have some sales. The EXCEPT operator or a NOT EXISTS predicate would be a good start.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  5. #5
    Join Date
    May 2008
    Posts
    277
    Quote Originally Posted by lazyme View Post
    How should I write a subquery to count the number of stores the have 0 sales for each particular item?
    For the moment, let's not worry about the subquery. The first thing you need to do is determine the number of sales per store per item. This should be a relatively straightforward query, and we can use this in your final query.

Posting Permissions

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