Solved

join type or sub query join

Posted on 2011-03-24
8
583 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
 
LVL 27

Expert Comment

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

Tom
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.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now