IPL-ExploratoryDataAnalysis - With MySQL
IPL-ExploratoryDataAnalysis - With MySQL
# --Distinct values
select distinct year(m.date) as 'Year of Match' from ipl.matches m
order by 1;
# --Find season winner for each season (season winner is the winner of the last match
of each season)
select distinctrow m.season, m.winner from ipl.matches m
order by m.season desc;
select distinct season, winner from ipl.matches order by season desc;
# --Data Aggregation
select winner,win_by_wickets,max(win_by_runs) from ipl.matches
#where winner='Mumbai Indians'
group by winner
order by 3 desc;
# --How many teams have word royal in it (could be anywhere in the team name, any
case)
SELECT distinct team1 FROM ipl.matches where lower(team1) like lower('%Royal%');
# --Group by - Maximum runs by which any team won a match per season
select season,max(win_by_runs) from ipl.matches
group by season
order by 1;
# --Name and number of wickets by bowlers who have taken more than or equal to
100 wickets in ipl
select bowler,count(player_dismissed) as NoWicket_Taken,dismissal_kind from
ipl.deliveries
where dismissal_kind <>""
group by bowler
having count(player_dismissed) >=100
order by NoWicket_Taken desc
limit 10;
) Temp
where Temp.rn<3;
# --Window Functions - (CTE) -- Combine column date from matches with table
deliveries to get data by year
*what is CTE ?
A common table expression (CTE) is a named temporary result set that exists within the scope of a
single statement and that can be referred to later within that statement, possibly multiple times.
with
t1 as (select id,season,date,city,team1,team2,winner from ipl.matches),
t2 as (select matchid,batting_team,bowling_team from ipl.deliveries)
select distinct
t1.season,t1.date,t1.city,t1.team1,t1.team2,t2.batting_team,t2.bowling_team,
t1.winner
from t1 inner join t2 on t1.id=t2.matchid;