Skip to content
(SQL) Project: Producing Football Insights (Case: UEFA Champions League/UCL) for a Sports Media Agency [Updated Version]
  • AI Chat
  • Code
  • Report
  • Analyze UEFA Champion's League Soccer (UCL) Games using Snowflake SQL

    The following Snowflake database containing data on the UEFA Champions League between 2020 and 2022.

    The UEFA Champions League, often called the Champions League, is a preeminent annual soccer competition that captivates fans worldwide. Established in 1955 as the European Champion Clubs' Cup, it evolved into the UEFA Champions League in 1992, broadening its appeal. The modern format features 32 top-tier club teams selected based on their domestic league performance, adding to the intrigue.

    This electrifying event transcends sports, becoming a celebration of unity, culture, and national pride. Fans, draped in their countries' colors, create an electric atmosphere, making the tournament as much about the spectators as the players.Financially, the Champions League is a lifeline for clubs, boosting revenues and offering transformative opportunities. Nevertheless, it sparks debates about wealth disparities in European soccer.

    The Champions League is synonymous with historic rivalries, underdog triumphs, and individual brilliance. For players, it represents a career pinnacle, while for fans, it's a cultural phenomenon. The iconic anthem and rituals enrich the soccer experience. In 200 words, the UEFA Champions League is the epitome of European soccer excellence, offering unforgettable moments, financial rewards, and a unique cultural impact, with 32 top clubs adding to its allure.

    Schema name: SOCCER

    Table Name(s): TBL_UEFA_2020 | TBL_UEFA_2021 | TBL_UEFA_2022

    Note : All three tables have same column names and data types

    ColumnDefinitionData type
    STAGEStage of the MarchVARCHAR(50)
    DATEWhen the match occurred.DATE
    PENSDid the match end with penaltyVARCHAR(50)
    PENS_HOME_SCOREIn case of penalty, score by home teamVARCHAR(50)
    PENS_AWAY_SCOREIn case of penalty, score by away teamVARCHAR(50)
    TEAM_NAME_HOMETeam home nameVARCHAR(50)
    TEAM_NAME_AWAYTeam away nameVARCHAR(50)
    TEAM_HOME_SCORETeam home scoreNUMBER
    TEAM_AWAY_SCORETeam away scoreNUMBER
    POSSESSION_HOMEBall possession for the team homeFLOAT
    POSSESSION_AWAYBall possession for the team awayFLOAT
    TOTAL_SHOTS_HOMEMethod of transport usedNUMBER
    TOTAL_SHOTS_AWAYMillions of journeys, measured in decimalsNUMBER
    SHOTS_ON_TARGET_HOMETotal shot for team homeFLOAT
    SHOTS_ON_TARGET_AWAYTotal shot for team awayFLOAT
    DUELS_WON_HOMEduel win possession of ball - for home teamNUMBER
    DUELS_WON_AWAYduel win possession of ball - for away teamNUMBER
    PREDICTION_TEAM_HOME_WINProbability of home team to winFLOAT
    PREDICTION_DRAWProbability of drawFLOAT
    PREDICTION_TEAM_AWAY_WINProbability of away team to winFLOAT
    LOCATIONMillions of journeys, measured in decimalsVARCHAR(50)
    Note that in Snowflake all databases, tables, and columns are upper case by default.

    You will execute SQL queries to answer three questions, as listed in the instructions.

    Spinner
    DataFrameavailable as
    df
    variable
    -- Overview of the 20/21 Season
    SELECT * FROM SOCCER.TBL_UEFA_2020
    Spinner
    DataFrameavailable as
    df6
    variable
    SELECT STAGE
    FROM SOCCER.TBL_UEFA_2020
    WHERE STAGE NOT LIKE 'Group stage: Matchday%'
    GROUP BY STAGE
    ORDER BY STAGE
    Spinner
    DataFrameavailable as
    df7
    variable
    -- Group Stage in UCL
    
    SELECT STAGE
    FROM SOCCER.TBL_UEFA_2022
    WHERE STAGE LIKE '%Group stage: Matchday%' AND STAGE NOT LIKE 'Group stage: Matchday%'
    GROUP BY STAGE
    ORDER BY STAGE
    Spinner
    DataFrameavailable as
    df12
    variable
    -- KO Stage in UCL 
    
    SELECT STAGE
    FROM SOCCER.TBL_UEFA_2022
    WHERE NOT (STAGE LIKE '%Group stage: Matchday%')
    GROUP BY STAGE
    ORDER BY STAGE
    Spinner
    DataFrameavailable as
    df19
    variable
    -- Participating Teams in UCL 20/21 Season
    
    SELECT TEAM_NAME_HOME AS team_name 
    FROM SOCCER.TBL_UEFA_2020
    GROUP BY TEAM_NAME_HOME
    
    UNION 
    
    SELECT TEAM_NAME_AWAY AS team_name
    FROM SOCCER.TBL_UEFA_2020
    GROUP BY TEAM_NAME_AWAY

    1. Find the team which capitalized the most on home advantage

    Find the top 3 teams which scored highest goals while playing at their home ground in UEFA Champions League 2020-21. The output should contain two columns: TEAM_NAME_HOME and TEAM_HOME_SCORE arranged in descending order of TEAM_HOME_SCORE.

    Spinner
    DataFrameavailable as
    TEAM_HOME_WITH_MOST_GOALS
    variable
    -- TEAM_HOME_WITH_MOST_GOALS
    SELECT TEAM_NAME_HOME, TEAM_HOME_SCORE 
    FROM SOCCER.TBL_UEFA_2020
    ORDER BY TEAM_HOME_SCORE DESC
    LIMIT 3
    Spinner
    DataFrameavailable as
    df13
    variable
    -- TOTAL_TEAM_WITH_MOST_GOALS AT HOME in 20/21 Season
    SELECT TEAM_NAME_HOME, SUM(TEAM_HOME_SCORE) AS total_goals_home
    FROM SOCCER.TBL_UEFA_2020
    GROUP BY TEAM_NAME_HOME
    ORDER BY total_goals_home DESC
    Spinner
    DataFrameavailable as
    df14
    variable
    -- TEAM_WITH_MOST_GOALS AT AWAY in 20/21 Season
    SELECT TEAM_NAME_AWAY, SUM(TEAM_AWAY_SCORE) AS total_goals_away
    FROM SOCCER.TBL_UEFA_2020
    GROUP BY TEAM_NAME_AWAY
    ORDER BY total_goals_away DESC
    Spinner
    DataFrameavailable as
    df11
    variable
    -- team with most goals scored during the 20/21 season UCL campaign
    
    SELECT team_name, SUM(total_goals) AS total_goals
    FROM (
        SELECT TEAM_NAME_HOME AS team_name, SUM(TEAM_HOME_SCORE) AS total_goals
        FROM SOCCER.TBL_UEFA_2020
        GROUP BY TEAM_NAME_HOME
    
        UNION ALL
    
        SELECT TEAM_NAME_AWAY AS team_name, SUM(TEAM_AWAY_SCORE) AS total_goals
        FROM SOCCER.TBL_UEFA_2020
        GROUP BY TEAM_NAME_AWAY
    ) AS combined_goals
    GROUP BY team_name
    ORDER BY total_goals DESC;
    Spinner
    DataFrameavailable as
    df15
    variable
    -- team with most goals conceded during the 20/21 season UCL campaign
    SELECT team_name, SUM(total_goals) AS total_goals
    FROM (
        SELECT TEAM_NAME_HOME AS team_name, SUM(TEAM_AWAY_SCORE) AS total_goals
        FROM SOCCER.TBL_UEFA_2020
        GROUP BY TEAM_NAME_HOME
    
        UNION ALL
    
        SELECT TEAM_NAME_AWAY AS team_name, SUM(TEAM_HOME_SCORE) AS total_goals
        FROM SOCCER.TBL_UEFA_2020
        GROUP BY TEAM_NAME_AWAY
    ) AS combined_goals
    GROUP BY team_name
    ORDER BY total_goals DESC;
    Spinner
    DataFrameavailable as
    df18
    variable
    -- The Champion of 20/21 UCL campaign overview throughout the season
    
    SELECT DISTINCT STAGE AS stage, TEAM_NAME_HOME, TEAM_NAME_AWAY, TEAM_HOME_SCORE, TEAM_AWAY_SCORE 
    FROM SOCCER.TBL_UEFA_2020
    WHERE TEAM_NAME_HOME LIKE '%Chelsea%' OR TEAM_NAME_AWAY LIKE '%Chelsea%'
    ORDER BY stage
    Spinner
    DataFrameavailable as
    df16
    variable
    -- team with most clean sheets during the 20/21 season UCL campaign
    SELECT team_name, SUM(clean_sheets) AS total_clean_sheets
    FROM (
        SELECT TEAM_NAME_HOME AS team_name, 
    		SUM(CASE 
    			WHEN TEAM_AWAY_SCORE = 0 AND TEAM_HOME_SCORE = 0 THEN 1 
    			WHEN TEAM_AWAY_SCORE = 0 AND TEAM_HOME_SCORE > 0 THEN 1
    			ELSE 0 END) AS clean_sheets
        FROM SOCCER.TBL_UEFA_2020
        GROUP BY stage, TEAM_NAME_HOME
    
        UNION ALL
    
        SELECT TEAM_NAME_AWAY AS team_name, 
    		SUM(CASE 
    			WHEN TEAM_AWAY_SCORE = 0 AND TEAM_HOME_SCORE = 0 THEN 1 
    			WHEN TEAM_AWAY_SCORE > 0 AND TEAM_HOME_SCORE = 0 THEN 1
    			ELSE 0 END) AS clean_sheets
        FROM SOCCER.TBL_UEFA_2020
        GROUP BY stage, TEAM_NAME_AWAY
    ) AS cleaned_sheets
    GROUP BY team_name
    ORDER BY total_clean_sheets DESC;