Please Help with Query for little league football site

Discussion in 'MySQL' started by eelyak, Jan 4, 2011.

  1. #1
    this thing is beating me to death. i've done pretty good so far but need help with thie query. I'm not a dba nor play one on TV. Below is the relevant data.


    TABLE [roster_stats]
    week e_id gameid teamid athleteid rushattempts rushlong rushtds rushyards
    1 195 0 27 218 3 20 0 30
    1 195 0 31 144 2 50 1 38
    2 195 1 27 218 5 12 0 20
    2 195 1 31 144 2 7 1 12
    3 195 2 27 218 7 12 3 50
    3 195 2 31 144 4 35 1 50

    TABLE [roster_gamestats]
    week eid gameid teamid score
    0 195 0 27 10
    0 195 0 31 7
    1 195 1 27 21
    1 195 1 31 14
    2 195 2 27 21
    2 195 2 31 28

    TABLE [roster_players]
    athleteid firstname lastname posid
    218 Frankie Edger 3
    144 Greg Jackson 3

    TABLE [roster_teams]
    teamid teamname
    27 Firebugs
    30 Bumblebees

    TABLE [roster_positions]
    posid posname
    3 RB


    select on athleteid

    week gameid team athleteid firstname lastname position att long tds yds
    1 0 Firebugs 218 Frankie Edger RB 3 20 0 30
    2 1 Firebugs 218 Frankie Edger RB 5 12 0 20
    3 2 Firebugs 218 Frankie Edger RB 6 12 0 50
    ...


    SELECT stats.gameid, gsa.teamid as awayteam, gsh.teamid as hometeam, gsa.score as awayscore, gsh.score as homescore
    FROM roster_stats as stats JOIN roster_gamestats as gsh JOIN roster_stats_gamestats gsa
    ON gsh.gameid = gsa.gameid AND gsh.teamid!=gsa.teamid AND gsh.gameid = stats.gameid AND gsa.gameid=stats.gameid where athleteid='218'

    Best I can do is get back 6 entry's per game.. if i group them and use Max(stats.rushattempts) or something along these lines i can semi get past it i think.. but would rather fix the query that work around it?

    Pls help :)
     
    eelyak, Jan 4, 2011 IP