Advertisement
amaimon02

2988 - Campeonato Cearense

Apr 5th, 2024 (edited)
1,246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.00 KB | None | 0 0
  1. SELECT
  2.   name,
  3.   COUNT(name) AS matches,
  4.   SUM(CAST(Vitorias AS int)) AS victories,
  5.   SUM(CAST(Derrotas AS int)) AS defeats,
  6.   SUM(CAST(Empate AS int)) AS draws,
  7.   (SUM(CAST(Vitorias AS int)) * 3) + (SUM(CAST(Empate AS int)) * 1) AS score
  8. FROM
  9.   (
  10.     SELECT  
  11.       teams.name,
  12.       matches.team_1 AS ID,
  13.       (matches.team_1_goals > matches.team_2_goals) AS Vitorias,
  14.       (matches.team_1_goals < matches.team_2_goals) AS Derrotas,
  15.       (matches.team_1_goals = matches.team_2_goals) AS Empate
  16.     FROM
  17.       teams
  18.       INNER JOIN matches ON matches.team_1 = teams.id
  19.     UNION ALL
  20.     SELECT
  21.       teams.name,
  22.       matches.team_2 AS ID,
  23.       (matches.team_2_goals > matches.team_1_goals) AS Vitorias,
  24.       (matches.team_2_goals < matches.team_1_goals) AS Derrotas,
  25.       (matches.team_2_goals = matches.team_1_goals) AS Empate
  26.     FROM
  27.       teams
  28.       INNER JOIN matches ON matches.team_2 = teams.id
  29.   ) AS tabela
  30. GROUP BY
  31.   name
  32. ORDER BY
  33.     score DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement