Jump to content

SQL query problem using Group By


smurfsdabomb

Recommended Posts

"Select Username, SUM(Score) FROM PlayerUpdate INNER JOIN Table1 ON Table1.PlayerID = Table2.PlayerID JOIN Table3 ON Table1.LeagueID = Table3.LeagueID WHERE Table1.LeagueID = " & Request.QueryString("titleleague") & " group by Table1.Username"

 

 

 

When I remove the group by and Sum part I get each of the results repeated twice presumably because of the table overlap but if I use Distinct Username I get the correct result and even if I use distinct within the SUM(distinct score) I get the correct result (though obviously a score of the same value would be discarded), but when I do the query as above I get a score of 28 instead of 14 because its taking the Score result twice, how do I ensure it is only summing it once?

 

Thanks!

 

Link to comment
Share on other sites

My bad, that should be Inner Join. Must have got deleted with the copy/paste over.

 

Any ideas whats going wrong? It might be something with the way I'm joining tables, if helps any this is the actual query without psuedonames and the relevant table data types.

 

SQLQuery = "Select FantasyTeamAssignment.Username, SUM(PlayerUpdate.CurrentScore) FROM PlayerUpdate INNER JOIN FantasyTeamAssignment ON FantasyTeamAssignment.PlayerID = PlayerUpdate.PlayerID JOIN LeagueSub ON FantasyTeamAssignment.LeagueID = LeagueSub.LeagueID WHERE FantasyTeamAssignment.LeagueID = " & Request.QueryString("titleleague") & " group by FantasyTeamAssignment.Username"

 

 

Tables

 

FantasyTeamAssignment - LeagueID (int), Username (char(15)), PlayerID (int)

 

LeagueSub - LeagueID (int), Username (nchar(15)), Active (nchar(10))

 

PlayerUpdate - PlayerID (int), Value (int), CurrentScore(int)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.