2

i have recently consolidated few database tables into one and made a better db design. i am about to adjust all the needed sql scripts which were based on the old table. my new db scheme looks like this: enter image description here

  • So basically i have a table for each player (fcs_spieler).
  • I have a table for each team (fcs_teams)
  • and i record in which year which player plays in which team (fcs_spieler2team).
  • it can also be that one player plays in two different teams the same year.
  • now i have a table fcs_sponsorenlauf. people can bet on a player.

I now would like to get the top 15 players with the most bets. I have tried 2 days now getting a working sql together without no luck. the problem is that either the sum is the double amount of what it should be or that players show up in the list which do not even have a single bet. in addition i am somehow not able to manage the case where a player plays in 2 teams the same year. what is wrong with my sql below? any suggestions, ideas? thanks

select s.spid, s.vorname,s.name,t.bezeichnung,sum(sp.betrag) as sum
from fcs_sponsorenlauf sp
join fcs_spieler s on (sp.2spieler = s.spid)
join fcs_spieler2team s2t on ( sp.2spieler = s2t.spieler and sp.year = s2t.year)
join fcs_teams t on (t.id = s2t.team)
where sp.betrag_art = 'fix'
AND sp.validated = 1
and sp.year = '2013'
group by s.spid
order by sum DESC
limit 15;
Rohit Gaikwad
  • 817
  • 2
  • 8
  • 24
dom
  • 652
  • 1
  • 16
  • 35
  • 1
    The answer is already given is this stackoverflow this [link][1] [1]: http://stackoverflow.com/questions/11337355/multiple-mysql-joins-with-aggregate-functions – Benjamin Mar 10 '14 at 06:42

0 Answers0