1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
DECLARE @saisId INT, @compId INT, @rangId INT, @nbPointsVictoire INT, @nbPointsNul INT, @nbPointsPerdu INT
SELECT @saisId = sais_id FROM dbo.saison WHERE sais_annee_debut = 2011 AND sais_annee_fin = 2012
SELECT @compId = comp_id FROM dbo.competition WHERE comp_nom = 'Top 14'
SELECT @rangId = rang_id FROM dbo.rang WHERE rang_nom = 'Saison régulière'
SET @nbPointsVictoire = 4
SET @nbPointsNul = 2
SET @nbPointsPerdu = 0
SELECT m.equi_nom, (@nbPointsVictoire * m.nb_matchs_gagnes + @nbPointsNul * m.nb_matchs_nuls + @nbPointsPerdu * m.nb_matchs_perdus + nb_points_bonus_defensif + nb_points_bonus_offensif) AS [nb_points],
(m.nb_points_bonus_defensif + m.nb_points_bonus_offensif) AS [nb_points_bonus], m.nb_matchs_joues, m.nb_matchs_gagnes, m.nb_matchs_nuls, m.nb_matchs_perdus, m.score_pour, m.score_contre, (m.score_pour - m.score_contre) AS [difference]
FROM
(
SELECT m.equi_nom, COUNT(*) AS [nb_matchs_joues], SUM(m.match_gagne) AS [nb_matchs_gagnes],
SUM(m.match_nul) AS [nb_matchs_nuls], SUM(m.match_perdu) AS [nb_matchs_perdus], SUM(m.score_pour) AS [score_pour],
SUM(m.score_contre) AS [score_contre], SUM(m.point_bonus_defensif) AS [nb_points_bonus_defensif], SUM(m.point_bonus_offensif) AS [nb_points_bonus_offensif]
FROM
(
-- match où l'équipe est à domicile
SELECT e.equi_nom, m.matc_score_domicile AS [score_pour], m.matc_score_exterieure AS [score_contre],
m.matc_d_deroulement,
CASE WHEN m.matc_score_domicile > m.matc_score_exterieure THEN 1 ELSE 0 END AS [match_gagne],
CASE WHEN m.matc_score_domicile = m.matc_score_exterieure THEN 1 ELSE 0 END AS [match_nul],
CASE WHEN m.matc_score_domicile < m.matc_score_exterieure THEN 1 ELSE 0 END AS [match_perdu],
CASE WHEN m.matc_score_exterieure - m.matc_score_domicile BETWEEN 1 AND 7 THEN 1 ELSE 0 END AS [point_bonus_defensif],
CASE WHEN m.matc_essai_domicile - m.matc_essai_exterieure >= 3 THEN 1 ELSE 0 END AS [point_bonus_offensif]
FROM dbo.match m
INNER JOIN dbo.equipe e ON m.equi_id_domicile = e.equi_id
WHERE m.comp_id = @compId
AND m.sais_id = @saisId
AND m.rang_id = @rangId
AND m.matc_d_deroulement <= GETDATE()
AND m.matc_a_ete_joue = 1
UNION
-- match où l'équipe est à l'extérieure
SELECT e.equi_nom, m.matc_score_exterieure AS [score_pour], m.matc_score_domicile AS [score_contre],
m.matc_d_deroulement,
CASE WHEN m.matc_score_domicile < m.matc_score_exterieure THEN 1 ELSE 0 END AS [match_gagne],
CASE WHEN m.matc_score_domicile = m.matc_score_exterieure THEN 1 ELSE 0 END AS [match_nul],
CASE WHEN m.matc_score_domicile > m.matc_score_exterieure THEN 1 ELSE 0 END AS [match_perdu],
CASE WHEN m.matc_score_domicile - m.matc_score_exterieure BETWEEN 1 AND 7 THEN 1 ELSE 0 END AS [point_bonus_defensif],
CASE WHEN m.matc_essai_exterieure - m.matc_essai_domicile >= 3 THEN 1 ELSE 0 END AS [point_bonus_offensif]
FROM dbo.match m
INNER JOIN dbo.equipe e ON m.equi_id_exterieure = e.equi_id
WHERE m.comp_id = @compId
AND m.sais_id = @saisId
AND m.rang_id = @rangId
AND m.matc_d_deroulement <= GETDATE()
AND m.matc_a_ete_joue = 1
) m
GROUP BY m.equi_nom
) m
ORDER BY nb_points DESC |
Partager