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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Self join problem

Status
Not open for further replies.

ponderdj

MIS
Dec 10, 2004
135
US
Hello All,

This started out as a report question, but has become a query question...

I have created a self join so that I may compare a field to itself. I want to list a count of [PDC](which will give me the # of transactions), and I want a sum of [MRC] per buyer, (which will give me total money spent per buyer)
Where [selling program]="TRNB" There are like 15 different buyers, and I don't want to write a seperate query for each buyer.

The query works fine, the problem occurs when I put it into a report(or in a bigger report as a subreport) and attempt to sum the count of [PDC] and sum [MRC]
I receive the error, "Multi-Level group clause is not allowed in subquery."

I came up with a work-around that works only if you run the query first, then close it, then run the report. (Don't ask me why) You can look at the semi-solution here:

I think that I need to re-write the query, is there a better way to do this without writing a seperate query from the seller to each buyer?

The SQL is below with some redundancy omitted:
Code:
SELECT BaseLine1.[Buying Program], BaseLine1.[Selling Program], (SELECT Count([CSA]) FROM tblISCCSAsbaseline WHERE [Buying Program]=BaseLine1.[Buying Program] And [Selling Program]="TRNB") AS CountOfPDC, (SELECT SUM([Total MRC (Baseline)]) FROM tblISCCSAsbaseline WHERE  [Selling Program]="TRNB" AND BaseLine1.[Buying Program]=[Buying Program]) AS MRC, (SELECT SUM([Total MRC (Baseline)]) FROM tblISCCSAsbaseline WHERE  [Selling Program]="TRNB") AS Total, (SELECT SUM([October MRC]) FROM tblISCCSAsbaseline WHERE Baseline1.[Buying Program] =tblISCCSAsbaseline.[Buying Program] AND [Selling Program]="TRNB") AS [October 04] 
FROM tblISCCSAsbaseline AS BaseLine1
GROUP BY BaseLine1.[Buying Program], BaseLine1.[Selling Program]
HAVING ((BaseLine1.[Selling Program])="TRNB");

Hope that made sense,
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top