Solved

join type or sub query join

Posted on 2011-03-24
8
589 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

685 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