Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

join type or sub query join

Posted on 2011-03-24
8
Medium Priority
?
599 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 1000 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 1000 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

886 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