Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
VBScab
Starting Member
5 Posts |
Posted - 2006-05-17 : 13:19:54
|
| I have a bunch of tables for my basketball club's d/b. I want to be able to interrogate them to build a web page showing player stats. For example, I want a table showing the top 5 scorers, top 5 3-point scorers, etc. What's got me foxed is how to join it all up and then sort it into the top 5 order. The main tables in question are T_Member, T_Fixture, T_Season and T_FixtureTeam:T_Member:MemberNo, FirstName, LastName, (etc)T_Fixture:FixtureNo, SeasonNo, MatchDate, (etc)T_Season:SeasoNo, SeasonDescription, SeasonStartDate, SeasonEndDate, CurrentSeasonT_FixtureTeam:FixtureNo, MemberNo, 2Points, 3Points,Fouls,FreeShotAttempts,FreeShotsHit,AssistsWhere you see the same field name, that field data is common for all tables that it appears in. In other words, for example, the T_FixtureTeam 'FixtureNo' and 'MemberNo' fields are made up of 'T_Fixture.FixtureNo' and 'T_Member.MemberNo' respectively.Ready?The user will select a season at the top of the page (although there's a default to the current season (CurrentSeason is a Boolean field). The query needs to:- Find all fixtures in that season- Find all members who played in those fixtures- Find the top 5 3-point scorers (or whatever stat I'm gathering) for those matches- Sort the resulting dataI figure I need a JOIN on MemberNo but, as I say, the rest of it has my head spinning.TIA |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-05-18 : 02:13:00
|
This should put you on trackSELECT TOP 5 M.MemberNo, M.FirstName, M.LastName, SUM(3Points)FROM T_Member MINNER JOIN T_FixtureTeam TON T.MemberNo = M.MemberNoINNER JOIN T_Fixture FON F.FixtureNo = T.FixtureNoINNER JOIN T_Season SON S.SeasoNo = F.SeasonNoWHERE CurrentSeason = 1GROUP BY M.MemberNo, M.FirstName, M.LastNameORDER BY SUM(3Points) DESC -- This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those. |
 |
|
|
|
|
|
|
|