Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

relationship of fields for sum function

Status
Not open for further replies.

cvaccess

Technical User
Jun 26, 2002
55
US
I have three tables:

edi_current is table with fields:Date, TP, Batch, Bundle, Beginning,Ending,Accepted, Rejected, EDI_Batch

pend_summary is table with fields:RPT_DATE, TP_NUM,Pends, Total

trading partners is table with field: tradingPartnerNum

My current problem is the sum of the pended total. The Pended shows the sum of the total records of the edi_current table multiplied by the total field in the pend_summary table. I want it to get the sum of each TP within the total field in the pend_summary and divide that by the accepted field in the EDI_current based on a specific date.

pend_summary table data:
rpt_date tp_num total
5/2/2002 p09 21
5/3/2002 p15 1

edi_current table data:
date tp accepted
5/1/2002 p09 245
5/10/2002 p15 300
5/9/2002 p01 200

trading partners table data:
tradingPartnerNum
p01
p09
p15
p20

So with the below query the Pended,output field, shows 63 (21 x 3 records from edi_current)for p09 and 3 (1 x 3 records from edi_current)for p15.

SELECT DISTINCTROW pend_summary.TP_NUM AS TP, Sum(pend_summary.TOTAL) AS Pended, Sum(edi_current.ACCEPTED) AS Accept, Sum(pend_summary.[total])/Sum(edi_current.[accepted]) AS [Pend %]
FROM edi_current, [trading partners] INNER JOIN pend_summary ON [trading partners].tradingPartnerNum = pend_summary.TP_NUM
WHERE (((pend_summary.RPT_DATE) Between [Enter Starting Create Date:] And [Enter Ending Create Date:]))
GROUP BY pend_summary.TP_NUM
HAVING ((((Sum([pend_summary].[total])/Sum([edi_current].[accepted])))>[Enter Pend % as a whole number]/100))
ORDER BY pend_summary.TP_NUM, Sum(pend_summary.[total])/Sum(edi_current.[accepted]) DESC;

Why does this happen? Do I have the relationships joined wrong?

Please help.

Thank you.

cvaccess



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top