× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Brian

You select in your statement for plantcode = '1' but seem to want other plants - I'll assume that is incorrect.

I would start out with joining the 3 tables on plant code and part number, then group by those fields, plus the bin type -

select a.plantcode, a.partno, b.bintype, count(*)
from tablea a join tableb b
on a.plantcode = b.plantcode and a.partno = b.partno
join tablec c
on a.plantcode = c.plantcode and a.partno = c.partno
where c.shiptype = 'PS'
and a.scyy||a.scmm||a.scdd = '201129'
group by a.plantcode, a.partno, b.bintype

You could refine it some with a couple table-expressions, either correlated or nested - one would be a select from a where a.scyy, etc. The other would be select from c where shiptype = 'PS' - this might make it run faster.

Not tested - just from memory here!

Hmmm?
Vern


On 2/22/2011 1:05 PM, Brian Piotrowski wrote:
Hi All,

I'm trying to consolidate three tables into a single result and I'm wondering if someone can give me a few ideas....

I have these tables:

TABLE A
Plant Code
Part Number
Part Colour
Scan Date (in three integer fields: YY, MM, DD (don't ask - the legacy programmers did not know how to use timestamps!))

TABLE B
Plant Code
Part Number
Bin Type

Table C
Plant Code
Part Number
Ship Type

What I want to do is combine the values into a result that has these fields for 02/09/2011:
Bin Type
Quantity for each bin type

Quantity is a sum of each bin type for the selected plant/part #.
IE:
Plant 1, Part: 12345, Bin Type: X1
Plant 1, Part: 67711, Bin Type: X2
Plant 2, Part: 67711, Bin Type: X2
Plant 3, Part: 90009, Bin Type: X3
Plant 2, Part: 90191, Bin Type: X1
Plant 1, Part: 12345, Bin Type: X1

If the above was entered into the system, I would expect the report to be:
Plant Code | Part Number | Bin Type | Quantity
1 | 12345 | X1 | 2
1 | 67711 | X2 | 1
2 | 67711 | X2 | 1
3 | 90009 | X3 | 1
2 | 90191 | X1 | 1

However, this is not the case - I am getting an insane amount of records when I try this (I know it is incorrect because one of the bins says we brought in over three million of them in a single day!!):

select b.bintype, count(b.bintype)
from tablea a, tableb b, tablec c
where a.partno = b.partno and a.partno = c.partno
and a.plantcode = '1' and c.shiptype = 'PS'
and a.scyy||a.scmm||a.scdd = '201129'
group by b.bintype

Anyone have any idea how I can rewrite this statement so that it gives me the correct values?

Thanks!

/b;


-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Brian Piotrowski
Assistant Mgr. - I.T.
Simcoe Parts Service, Inc.
Ph: 705-435-7814 x343
Fx: 705-435-5029
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
http://www.simcoeparts.com

Please consider the environment. Don't print this e-mail unless you really need to.

The information contained in this communication is confidential and intended only for the use of those to whom it is addressed. If you have received this communication in error, please notify me by telephone (collect if necessary) and delete or destroy any copies of it. Thank you!


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.