Solved

join type or sub query join

Posted on 2011-03-24
8
584 Views
Last Modified: 2012-05-11
So I have a query that is checking for the count of the items of a certain type with in a certain area of the warehouse.  What I now have to check is where we are selling the items -- one of the warehouse managers want to see if there is discontinued stock still out there.

So the two tables that have data on selling the item are cET and cETd, the cET table tells me where the item is selling (field name = SELLING) and the cETd table tells me whether the item is out on the floor (field name = AVAIL).  What I was going to use to join the tables is the sku number (field name = SKU) is in the myplay table and that links to the cET field by the same name and that gets you the field name SELLING.  The cET is linked to cETd by the fielld name cET_id and that gets you the field name AVAIL.

What I am having problems with is doing the join to check for both conditions.  Can someone help?
select tc, jhgh06, COUNT(*) AS OccNum
from db45.myplay
group by tc, jhgh06
Order by tc, jhgh06

Open in new window

0
Comment
Question by:iceman19330
8 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 250 total points
ID: 35210802
i hope i understood you
are you looking for something like:

select tc, jhqh06, count(*) as OccNum
from db45.myplay t1 join cet t2 on t1.sku = t2.sku
  join cetd t3 on t2.cet_id = t3.cet_id
group by tc, jhqh06
order by tc, jhqh06
0
 

Author Comment

by:iceman19330
ID: 35211229
Then would I put in a where clause to say where SELLING = '0' and AVAIL = '0'?
0
 
LVL 2

Assisted Solution

by:choukssa
choukssa earned 250 total points
ID: 35219140
select tc, jhqh06, count(*) as OccNum
from db45.myplay t1 join cet t2 on t1.sku = t2.sku
  join cetd t3 on t2.cet_id = t3.cet_id
where t2.SELLING = '0' and t3.AVAIL = '0'
group by tc, jhqh06
order by tc, jhqh06

--choukssa
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 27

Expert Comment

by:tliotta
ID: 35219991
Are you sure you want "= 0" (equals 0) instead of "<> 0" (not equals 0)?

Tom
0
 

Author Comment

by:iceman19330
ID: 35220178
yes 0 = off, and 1 = on
0
 
LVL 27

Expert Comment

by:tliotta
ID: 35220983
So you want to list the COUNT(*) only from rows that have no SELLING and no AVAIL?

I now have to check ... where we are selling the items...

If SELLING = '0', isn't that a row indicating NOT SELLING? I suspect that I'm not understanding the design of this database.

If COUNT(*)>0 for rows where AVAIL=0, is that an indication that the item is at the location but not "out on the floor", e.g., in storage?

Tom
0
 

Author Comment

by:iceman19330
ID: 35222575
Ugh you are correct.  *hangs head in shame*  Not sure why that only dawned on me now.
0
 
LVL 27

Expert Comment

by:tliotta
ID: 35225577
No problem. I just wanted to be sure the direction was right.

Tom
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question