khaled salem
asked on
inner join SQL
Hi All:
I've two table approximately with same structure First table should be inner join with "agency" and the second should be inner join with the same table "agency"
First One: "tktrans"
agentid , tktno, fare, total, comm, issuedate
Second " extktrans"
agentid , tktno, fare, total, comm, issuedate
i'd like to make query to get me the count and sum of the both table. I'd wrote the following code but the result was incorrect
Err1.png
I've two table approximately with same structure First table should be inner join with "agency" and the second should be inner join with the same table "agency"
First One: "tktrans"
agentid , tktno, fare, total, comm, issuedate
Second " extktrans"
agentid , tktno, fare, total, comm, issuedate
i'd like to make query to get me the count and sum of the both table. I'd wrote the following code but the result was incorrect
SQL.Add('Select a.agentid, bb.Agency , count(a.agentid)+count(cc.agentid) as tktcount,Sum(a.Fare)+Sum(cc.Fare) as fare, sum(a.totax)+sum(cc.totax) as tax,');
SQL.Add('Sum((a.agentcomm*a.fare)/100)+Sum((cc.agentcomm*cc.fare)/100) as agentComm, Sum((a.OfficeComm*a.fare)/100)+Sum((cc.OfficeComm*cc.fare)/100) as OfficeComm, sum(a.grandtot)+sum(cc.grandtot) as grandtot,');
SQL.Add('Sum(a.grandtot)-(Sum((a.agentcomm*a.fare)/100)+Sum((a.OfficeComm*a.fare)/100))+Sum(cc.grandtot)-(Sum((cc.agentcomm*cc.fare)/100)+Sum((cc.OfficeComm*cc.fare)/100)) as Airlinesdue, sum(a.paid)+sum(cc.paid) as paid, sum(a.credit)+sum(cc.credit) as credit');
SQL.Add('From tktrans a');
SQL.Add('INNER join extktrans cc on a.agentid=cc.agentid');
SQL.Add('inner join Agencies bb on a.agentid=bb.agencyid');
SQL.add('where a.issuedate>= :D1 and a.issuedate<= :D2 and cc.issuedate>= :D1 and cc.issuedate<= :D2');
DETAILS.pngErr1.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A grading of "C" is the lowest possible- and considered very harsh. This is not a C grade answer as far as I can see. Please explain why you chose a C grading.
C should only be given for an incomplete solution that does not fully address or answer the question. ... The asker must justify giving a C grade and give the experts an opportunity to improve it.SEE: What grade should I award?
...
If you feel that an inappropriate grade has been awarded, you may use the Request Attention feature to contact the site Moderators, who are able to change the grade awarded at their discretion.
khaledsalem
I have requested attention on this question and hope you will re-consider the grading, or provide details on why the answer didn't meet your needs.
Thank you,
PortletPaul
I have requested attention on this question and hope you will re-consider the grading, or provide details on why the answer didn't meet your needs.
Thank you,
PortletPaul
when you say you are getting incorrect results are values smaller than expected?
The inner joins requires that both all tables tables have a match, is it possible for records to exist in tktrans that don't match to extktrans? (or vice-versa?)
perhaps try this join structure as a test:
Open in new window
some sample data from each table would help us identify a solution.At the extreme, it may pay to treat both transaction tables as independent subqueries, like this:
Open in new window