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

I am trying a self join that isn't

Status
Not open for further replies.

struth

Programmer
Aug 26, 2001
114
GB
I am trying a self join that isn't quite coming off because it involves adding up a users game points and counting the nuber of times that user has played that game. I can get Count() or Sum() working OK but not together. I've tried various ways of bracketing them but nothing is coming off. Frustrating day today :~(

SELECT Sum(Points) AS SSP
FROM BigGame
WHERE BigGameOK = varOK AND UserName = 'varUser'

Can you help me out... thanks

Struth

"Its life Jim, but not as we know it."
 
Well, I don't have table that I can test this on, but maybe try this:

SELECT Sum(Points) AS SSP,
(SELECT Count(Points)
FROM BigGame
WHERE BigGameOK = varOK and UserName='varUser'
) as PointCount
FROM BigGame
WHERE BigGameOK = varOK AND UserName = 'varUser'
 
I thought you had it there ...

but I got the too few parameters error. I'll keep messing about til I crack it .... or it cracks me.

Thanks
Struth "It's life Jim, but not as we know it!"
 
Nailed it! But don't ask me to explain it - total trial and error:

SELECT * FROM (SELECT (SELECT COUNT (*) FROM BigGame WHERE UserName = 'varUser' AND BigGameOK=varOK) AS PointCount, (SELECT Sum (Points)
FROM BigGame
WHERE UserName = 'varUser' AND BigGameOK=varOK) AS SSP FROM BigGame)

Think i'll go and have a wee drink now to celebrate.

Thanks for helping to set me on the right path.

Struth "It's life Jim, but not as we know it!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top