Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Please add ; after each select statement*/
- CREATE PROCEDURE soccerGameSeries()
- BEGIN
- /*SELECT CASE
- WHEN w.t1wins = w.t2wins
- THEN CASE
- WHEN w.t1Diff > w.t2Diff AND t1AwayWins > t2AwayWins THEN 1
- WHEN w.t1Diff < w.t2Diff AND t1AwayWins < t2AwayWins THEN 2
- ELSE 0 END
- WHEN w.t1wins > w.t2wins
- THEN 1 ELSE 2 END as winner */
- SELECT *
- FROM
- (
- SELECT
- SUM(CASE WHEN first_team_score > second_team_score OR (first_team_score = second_team_score AND match_host = 2) THEN 1 ELSE 0 end) as t1wins,
- SUM(CASE WHEN first_team_score < second_team_score OR (first_team_score = second_team_score AND match_host = 1) THEN 1 ELSE 0 end) as t2wins,
- MAX(first_team_score - second_team_score) as t1Diff,
- MAX(second_team_score - first_team_score ) as t2Diff,
- SUM(CASE WHEN first_team_score > second_team_score AND match_host = 2 then 1 ELSE 0 end) as t1AwayWins ,
- SUM(CASE WHEN second_team_score > first_team_score AND match_host = 1 then 1 ELSE 0 end) as t2AwayWins
- FROM scores
- ) w;
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement