SQL Server table league [closed]
I would like to build a table league from matches (scores and rounds).
I succceeded from my SQL Server database to calculate points for each teams and matches but I would like now to generate a table league.. (football)
Some one can help me please?
SELECT TOP (100) PERCENT dbo.jos_joomleague_matches.match_id, dbo.jos_joomleague_clubs.name AS Team, jos_joomleague_clubs_1.name AS Team2,
dbo.jos_joomleague_matches.match_date, dbo.jos_joomleague_matches.matchpart1_result, dbo.jos_joomleague_matches.matchpart2_result,
dbo.jos_joomleague_rounds.name,
CASE WHEN dbo.jos_joomleague_matches.matchpart1_result > dbo.jos_joomleague_matches.matchpart2_result THEN 3 WHEN dbo.jos_joomleague_matches.matchpart1_result
= dbo.jos_joomleague_matches.matchpart2_result THEN 1 ELSE 0 END AS ptsclub1HOME,
CASE WHEN dbo.jos_joomleague_matches.matchpart2_result > dbo.jos_joomleague_matches.matchpart1_result THEN 3 WHEN dbo.jos_joomleague_matches.matchpart2_result
= dbo.jos_joomleague_matches.matchpart1_result THEN 1 ELSE 0 END AS ptsclub2AWAY
FROM dbo.jos_joomleague_rounds INNER JOIN
dbo.jos_joomleague_clubs AS jos_joomleague_clubs_1 INN开发者_如何学CER JOIN
dbo.jos_joomleague_matches INNER JOIN
dbo.jos_joomleague_clubs ON dbo.jos_joomleague_matches.matchpart1 = dbo.jos_joomleague_clubs.id ON
jos_joomleague_clubs_1.id = dbo.jos_joomleague_matches.matchpart2 ON dbo.jos_joomleague_rounds.id = dbo.jos_joomleague_matches.round_id
ORDER BY dbo.jos_joomleague_matches.match_date
`
Start with an natural language description of your problem before you create tables. Think about the relationships:
A league
has many teams
. A match
has two teams
that play on a given date
and has a specific outcome
.
I see three tables: league
, team
, and match
. Start with those.
You're premature if you're thinking about queries already. Get the basic table structure right first.
精彩评论