vb.net - Grouping and Joining a Unioned Table. Having Problems -


the other day asked question , received helpful information assisted me far. having trouble taking data tables using union/group by.

the following code have tried. cannot seem find way make group player.

it showing this.

jono - 3 - 1 jono - 1 - 1 

when need show this

jono - 4 - 1  

i beginning if there better way perform code, please tell me :)

select [player],[played],[games won] (select p1.displayname [player], count(p1.displayname) [played], sum(iif(m.player2=m.winner, 1, 0)) [games won] ((tblmatch m) inner join tblplayers p1 on m.player2=p1.id) m.season = 3 group p1.displayname union select p2.displayname [player2], count(p2.displayname) [played], sum(iif(m.player1=m.winner, 1, 0)) [games won] ((tblmatch m) inner join tblplayers p2 on m.player1=p2.id) m.season = 3 group p2.displayname) 

my database layout is:

tblplayers (id,firstname,lastname,displayname,handicap,current)   tblseason  (id,season)   tblmatch   (id,matchdate,season,player1,player2,player1score,player2score,winner)   

and show list players name can come either player1 or player2 column , count number of games played player , these games count number of times won game.

thanks

wouldn't put group in outer query:

select [innerqueryalias].[player], sum([innerqueryalias].[played]) sumofplayed, sum([innerqueryalias].[games won]) [sumofgames won] (select p1.displayname [player], count(p1.displayname) [played], sum(iif(m.player2=m.winner, 1, 0)) [games won] ((tblmatch m) inner join tblplayers p1 on m.player2=p1.id) m.season = 3 group p1.displayname union select p2.displayname [player2], count(p2.displayname) [played], sum(iif(m.player1=m.winner, 1, 0)) [games won] ((tblmatch m) inner join tblplayers p2 on m.player1=p2.id) m.season = 3 group p2.displayname)  [innerqueryalias] group [innerqueryalias].[player]; 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -