January 31, 2006 at 5:55 am
Hi I am having trouble trying to figure out this sql query I need to display the opponents for a soccer team and display whether or not the team was at home or not at the moment I can display the two teams involved in the match and the stats I need but I don’t how to always get the other teams and display whether or not they were at home. This is my current query any help would be appreciated
Select homeClub.Name + ' v ' + awayClub.Name as Match, pz.DistanceCovered From Teams t
Join Person p on p.ID = t.PlayerID Join PZData pz on pz.TeamID = t.TeamID Join Match m on m.Id = t.MatchId
JOIN Squad homeSquad on m.SquadA = homeSquad.[ID]
JOIN Squad awaySquad on m.SquadB = awaySquad.[ID]
JOIN Club homeClub on homeSquad.ClubID = homeClub.[ID]
JOIN Club awayClub on awaySquad.ClubID = awayClub.[ID]
where t.ClubId in (select ClubID from Squad Where ID = 5)
and p.Id = 19
order by m.date asc
January 31, 2006 at 8:09 am
We need more information.
This part of the query indicates to me your only pulling a single team.
where t.ClubId in (select ClubID from Squad Where ID = 5)
and p.Id = 19
Please post some sample data and desired results.
February 1, 2006 at 10:55 am
February 2, 2006 at 1:21 am
As far as I can understand it, you have a player (person.ID) and club. The query should find all matches of this club in which the certain player has played, and display them accordingly, i.e. always the team that was playing at home comes first. The rest will probably be some additional info, like dates, results, distance the players had to travel etc., and it has no or little influence on the query. Hm... maybe "distance covered" has to be calculated only if the team was not playing at home, but that should be simple enough to do...?
If this is right, then tables should have following meaning:
Teams - list of players that took part in a certain match
Person - info about individual players
PZData - ???
Match - who played who, probably with result, date etc.; column SquadA contains club (squad) that played home, column SquadB contains club (squad) that played away.
Squad + Club - not really clear what is what, but together it should contain info about a team (maybe one club has several teams/squads/, like age groups under 16, under 21 etc.?). What is a bit confusing is that IN clause, since that looks as if it was the other way round, that a squad can have several clubs...? Please explain what is the difference between squad, club and team.
Is that right? Please correct any misunderstandings, explain the problem in more detail and show us some example. We should be able to solve this once we know what it is about.
HTH, Vladan
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply