Solved

join type or sub query join

Posted on 2011-03-24
8
581 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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 video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

25 Experts available now in Live!

Get 1:1 Help Now