BigRed1212
Technical User
Big post, sorry in advance.
I run a site for a local soccer league. I currently have all the pages which have the game schedule, team standings, and leading scorers, as well as the registered players database driven using ASP and an Access database. My problem is that the schedule table I use is embarrasingly non-normalized (I just use the table structure as a way to line up the elements for display). What I think I want to do is move toward proper tables and proper queries for information. I'm asking this here and not in "general database discussion" because my eye is toward the queries I need to have to drive my site and I think all the query experts are here.
A couple of tables are easy (I think).
tbl_Players (each record is a player):
player_id (autonumber, primarykey)
lname
fname
jersey_number
other basic demographic elements
team_number (from tbl_Teams)
paid_status
[this table loads from a Web form when the players register to play]
tbl_Goals_Scored (each record represents a goal scored):
player_id
game_id (from tbl_Games)
[I'll know Jones scored in the 3:00 game and I'll data enter his/her player id and the game id in a web interface I made]
tbl_Cards_Given (each record represents a card given):
player_id
game_id (from tbl_Games)
card_type
[I'll do this once where card_type is yellow and once where card_type is red]
After that I can think of a few more tables, but I start getting into deep water really quickly when I try to think of how to write the
queries I think I will need to produce the info I need to display.
I think I probably need a team table and a games table and I need some way to assign teams to a game.
tbl_Teams:
team_name
captain_id (player_id from tbl_Players)
team_number
tbl_Games
game_id
game_date
game_time
field_location
tbl_Game_Assignments????
game_id
team_number
(but this will duplicate because every game_id will be in twice - two teams per game- and it will look ultimately look suspiciously like the tbl_Schedule I do now with game_id, team1, team2, game_date, etc that seems nonnormalized with the repeating field).
From these tables I can display a team roster pretty simply:
select fname. lname, jersey_number, etc
from tbl_players
where team_number = whichever one I want at the moment
order by lname
Displaying the listing of goal scorers is
select b.lname, count(a.player_id)
from goals_scored a left join players b on a.player_id = b.player_id
group by lname
order by count (a.player_id) desc
(I will put in a dummy player number in the players table to handle unattributed own goals where a team scores on itself)
Problem is, I don't know how to do the big things. I think I want them to be query results:
1. Schedule. On this day, at this time, these two teams will play on this field. (I do this with the above mentioned horribly nonnormalized table now)
I don't know whether this can or should be done as a query or whether the thing to do is return the whole table(s) and march through it(tem) with some ASP loops somehow someway.
2. Results- The score of each game (team one beat team two x to y)
3. Standings- Team one has x victories, x losses, and x goals for and against.
We would know that for game 3 team green had 4 goals and team red had 3 goals. I would want to be able to calculate that team green won the game and had a record of was 1-0-0 (one win, zero losses, and zero ties) with 4 goals for and 3 goals against. I do the standings now by manually entering the goals for, goals against, and a 1 or zero for win, loss, or tie for each team for each game, and then summing and counting.
Any thoughts on any piece of this welcome. I've cruised the net and lurked around here for awhile but I haven't found the insight I need yet.
I run a site for a local soccer league. I currently have all the pages which have the game schedule, team standings, and leading scorers, as well as the registered players database driven using ASP and an Access database. My problem is that the schedule table I use is embarrasingly non-normalized (I just use the table structure as a way to line up the elements for display). What I think I want to do is move toward proper tables and proper queries for information. I'm asking this here and not in "general database discussion" because my eye is toward the queries I need to have to drive my site and I think all the query experts are here.
A couple of tables are easy (I think).
tbl_Players (each record is a player):
player_id (autonumber, primarykey)
lname
fname
jersey_number
other basic demographic elements
team_number (from tbl_Teams)
paid_status
[this table loads from a Web form when the players register to play]
tbl_Goals_Scored (each record represents a goal scored):
player_id
game_id (from tbl_Games)
[I'll know Jones scored in the 3:00 game and I'll data enter his/her player id and the game id in a web interface I made]
tbl_Cards_Given (each record represents a card given):
player_id
game_id (from tbl_Games)
card_type
[I'll do this once where card_type is yellow and once where card_type is red]
After that I can think of a few more tables, but I start getting into deep water really quickly when I try to think of how to write the
queries I think I will need to produce the info I need to display.
I think I probably need a team table and a games table and I need some way to assign teams to a game.
tbl_Teams:
team_name
captain_id (player_id from tbl_Players)
team_number
tbl_Games
game_id
game_date
game_time
field_location
tbl_Game_Assignments????
game_id
team_number
(but this will duplicate because every game_id will be in twice - two teams per game- and it will look ultimately look suspiciously like the tbl_Schedule I do now with game_id, team1, team2, game_date, etc that seems nonnormalized with the repeating field).
From these tables I can display a team roster pretty simply:
select fname. lname, jersey_number, etc
from tbl_players
where team_number = whichever one I want at the moment
order by lname
Displaying the listing of goal scorers is
select b.lname, count(a.player_id)
from goals_scored a left join players b on a.player_id = b.player_id
group by lname
order by count (a.player_id) desc
(I will put in a dummy player number in the players table to handle unattributed own goals where a team scores on itself)
Problem is, I don't know how to do the big things. I think I want them to be query results:
1. Schedule. On this day, at this time, these two teams will play on this field. (I do this with the above mentioned horribly nonnormalized table now)
I don't know whether this can or should be done as a query or whether the thing to do is return the whole table(s) and march through it(tem) with some ASP loops somehow someway.
2. Results- The score of each game (team one beat team two x to y)
3. Standings- Team one has x victories, x losses, and x goals for and against.
We would know that for game 3 team green had 4 goals and team red had 3 goals. I would want to be able to calculate that team green won the game and had a record of was 1-0-0 (one win, zero losses, and zero ties) with 4 goals for and 3 goals against. I do the standings now by manually entering the goals for, goals against, and a 1 or zero for win, loss, or tie for each team for each game, and then summing and counting.
Any thoughts on any piece of this welcome. I've cruised the net and lurked around here for awhile but I haven't found the insight I need yet.