varma-prasad / IPL-Analysis

Indian Premier League Analysis from 2008 to 2020

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IPL-Analysis

Table of Contents

Overview

  1. Perform Sports anlytics of famous cricketing festival of india "Indian Premier League" from 2008 to 2020
  2. WE have two data sets having Ball-by-Bal data and Match-Wise Data
  3. Create necessary table structure in PG Admin and import CSV data and perform analytics for different scenarios.
  4. Present queries to fetch data and results of the analysed data

Create Table Queries

Create a table named ‘deliveries’ with appropriate data types for columns

-- Table: public.deliveries
-- DROP TABLE IF EXISTS public.deliveries;
CREATE TABLE IF NOT EXISTS public.deliveries
(
    id integer NOT NULL,
    inning integer NOT NULL,
    over integer,
    ball integer,
    batsman character varying COLLATE pg_catalog."default",
    non_striker character varying COLLATE pg_catalog."default",
    bowler character varying COLLATE pg_catalog."default",
    batsman_runs integer,
    extra_runs integer,
    total_runs integer,
    is_wicket integer,
    dismissal_kind character varying COLLATE pg_catalog."default",
    player_dismissed character varying COLLATE pg_catalog."default",
    fielder character varying COLLATE pg_catalog."default",
    extras_type character varying COLLATE pg_catalog."default",
    batting_team character varying COLLATE pg_catalog."default",
    bowling_team character varying COLLATE pg_catalog."default",
    CONSTRAINT "FK_MATCH_ID" FOREIGN KEY (id)
        REFERENCES public.matches ("ID") MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.deliveries
    OWNER to postgres;

Create a table named ‘matches’ with appropriate data types for columns

-- Table: public.matches
-- DROP TABLE IF EXISTS public.matches;
CREATE TABLE IF NOT EXISTS public.matches
(
    id integer NOT NULL,
    city character varying COLLATE pg_catalog."default",
    date date,
    player_of_match character varying COLLATE pg_catalog."default",
    venue character varying COLLATE pg_catalog."default",
    neutral_venue integer,
    team1 character varying COLLATE pg_catalog."default",
    team2 character varying COLLATE pg_catalog."default",
    toss_winner character varying COLLATE pg_catalog."default",
    toss_decision character varying COLLATE pg_catalog."default",
    winner character varying COLLATE pg_catalog."default",
    result character varying COLLATE pg_catalog."default",
    result_margin integer,
    eliminator "char",
    method character varying COLLATE pg_catalog."default",
    umpire1 character varying COLLATE pg_catalog."default",
    umpire2 character varying COLLATE pg_catalog."default",
    CONSTRAINT "IPL_MATCH_pkey" PRIMARY KEY (id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.matches
    OWNER to postgres;

Analysis1

Write a query to fetch the year-wise total runs scored at Eden Gardens and order it in the descending order of total runs scored

select 
	to_char(date,'yyyy'),sum(total_runs)
from 
	deliveries d inner join matches m
	on  m.id = d.id
where 
	venue = 'Eden Gardens'
group by 
	to_char(date,'yyyy');

Output:
image

Analysis2

Fetch data of all the matches where the result mode is ‘runs’ and margin of victory is more than 100 runs.

select 
	* 
from 
	matches
where 
	result = 'runs' and result_margin > 100;

Output:
image

Analysis3

Write a query to fetch the total number of boundaries scored by each team

select 
	batting_Team,ball_result,count(*) as Boundaries
from 
	deliveries_v02
where
	ball_result in ('Four','Six')
group by
	batting_Team,ball_result
order by 
	Ball_result Desc, Boundaries desc;

Output:
image

Analysis4

Write a query to get the top 5 bowlers who conceded maximum extra runs

select 
	Bowler, sum(Extra_Runs) as Total_Extras
from
	deliveries
group by 
	Bowler
order by 
	Total_Extras desc
limit 5;

Output:
image

Analysis5

Write a query to fetch the total number of boundaries and dot balls

select 
	ball_result,count(*)
from 
	deliveries_v02
where
	ball_result in ('Dot','Four','Six')
group by
	ball_result;

Output:
image

🛠 Tools used

Authors

🛠 Skills

SQL, ETL, Python, Power BI...

🔗 Links

linkedin

About

Indian Premier League Analysis from 2008 to 2020