mysql - multiple joins and aggregate function -


i have consolidated few database tables 1 , made better db design. adjust needed sql scripts based on old table. new db scheme looks this: enter image description here

  • so have table each player (fcs_spieler).
  • i have table each team (fcs_teams)
  • and record in year player plays in team (fcs_spieler2team).
  • it can 1 player plays in 2 different teams same year.
  • now have table fcs_sponsorenlauf. people can bet on player.

i top 15 players bets. have tried 2 days getting working sql without no luck. problem either sum double amount of should or players show in list not have single bet. in addition somehow not able manage case player plays in 2 teams same year. wrong sql below? suggestions, ideas? thanks

select s.spid, s.vorname,s.name,t.bezeichnung,sum(sp.betrag) sum fcs_sponsorenlauf sp join fcs_spieler s on (sp.2spieler = s.spid) join fcs_spieler2team s2t on ( sp.2spieler = s2t.spieler , sp.year = s2t.year) join fcs_teams t on (t.id = s2t.team) sp.betrag_art = 'fix' , sp.validated = 1 , sp.year = '2013' group s.spid order sum desc limit 15; 


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -