If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Using SubQuery to Count 0 Sales Stores

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-13-11, 15:00
lazyme lazyme is offline
Registered User
 
Join Date: Oct 2007
Posts: 12
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 16:17.
Reply With Quote
  #2 (permalink)  
Old 06-13-11, 16:12
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
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.
Reply With Quote
  #3 (permalink)  
Old 06-13-11, 16:20
lazyme lazyme is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 06-14-11, 10:02
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #5 (permalink)  
Old 06-14-11, 11:46
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On