0% found this document useful (0 votes)
18 views

Final SQL Project

Uploaded by

yash sontakke
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Final SQL Project

Uploaded by

yash sontakke
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Task :1

YOUR FIRST PRIORITY IS TO GET 2-3 PLAYERS WITH HIGH S.R WHO HAVE FACED AT LEAST 500
BALLS.AND TO DO THAT YOU HAVE TO MAKE A LIST OF 10 PLAYERS YOU WANT TO BID IN THE
AUCTION SO THAT WHEN YOU TRY TO GRAB THEM IN AUCTION YOU SHOULD NOT PAY THE
AMOUNT GREATER THAN YOU HAVE IN THE PURSE FOR A PARTICULAR PLAYER.

Solution:
select batsman,sum(batsman_runs) as total_run, sum(ball) as
ball_face,

(sum(batsman_runs)*100/ sum(ball)) as strike_rate from


ipl_ball
group by batsman
having sum(ball) >=500
order by strike_rate desc
limit 10;
OUTPUT TASK:1
TOP 10 HIGH STRIKE RATE BATSMAN
batsman total_run ball_face strike_rate

AD Russell 1517 3423 44

MM Ali 309 709 43

SP Narine 892 2060 43

BCJ Cutting 238 550 43

N Pooran 521 1222 42

HH Pandya 1349 3335 40

AB de Villiers 4849 11847 40

MJ Guptill 270 670 40

CH Morris 551 1348 40

GJ Maxwell 1505 3721 40


TOP 10 HIGH STRIKE RATE BATSMAN
HIEGH STRIKE RATE BATSMAN
GJ Maxwell
CH Morris
MJ Guptill
AB de Villiers
HH Pandya strike_rate

N Pooran
BCJ Cutting
SP Narine
MM Ali
AD Russell
38 39 40 41 42 43 44 45
TASK :2
Now you need to get 2-3 players with good Average who have played more the 2 ipl
seasons . And to do that you have to make a list of 10 players you want to bid in the
auction so that when you try to grab them in auction you should not pay the amount
greater than you have in the purse for a particular player.

• Solution:

select batsman, count(distinct id) as matches,


sum(batsman_runs) as total_run ,
sum(is_wicket) as out_sum,
sum(batsman_runs)/sum(is_wicket) as average
from ipl_ball
group by batsman
having count(distinct id) >28
order by average desc
limit 10;
OUTPUT TASK:2
TOP 10 GOOD AVERAGE BATSMAN
batsman matches total_run out_sum average

AB de Villiers 156 4849 114 42

KL Rahul 72 2647 62 42

JP Duminy 75 2029 49 41

CH Gayle 131 4772 116 41

ML Hayden 32 1107 27 41

DA Warner 142 5254 126 41

LMP Simmons 29 1079 27 39

KS Williamson 52 1619 41 39

MEK Hussey 58 1977 52 38

SE Marsh 69 2477 64 38
TOP 10 GOOD AVERAGE BATSMAN
average

42 42
41 41 41 41
39 39
38 38

e rs h ul i ny y le e n
n er n s o n
se y
rsh
i l li Ra m a y d ar m
o s s a
V L D u H
G
H a W i m l i am H u
E
M
e K C L i l K S
d JP M DA PS W E
AB LM KS
M
TASK:3
Now you need to get 2-3 Hard-hitting players who have scored most runs in
boundaries and have played more the 2 ipl season. To do that you have to make a list
of 10 players you want to bid in the auction so that when you try to grab them in
auction you should not pay the amount greater than you have in the purse for a
particular player.
Solution:
SELECT batsman, SUM(batsman_runs) AS total_run,
sum(case when batsman_runs > 3 then batsman_runs else null end) as boundaries,
(sum(case when batsman_runs > 3 then batsman_runs else null end) * 100
/sum(batsman_runs)) as percentage
FROM ipl_ball
GROUP BY batsman
having count(distinct id) >28
order by percentage desc
LIMIT 10;
OUTPUT TASK:3
TOP 10 HARD HITTER BATSMAN
batsman total_run boundaries percentage

SP Narine 892 729 81

AD Russell 1517 1194 78

CH Gayle 4772 3630 76

ST Jayasuriya 768 575 74

V Sehwag 2728 1972 72

AC Gilchrist 2069 1508 72

DR Smith 2385 1687 70

CA Lynn 1280 890 69

Harbhajan Singh 829 568 68

SR Watson 3874 2649 68


HARD HITTER BATSMAN
boundaries total_run percentage
2649
SR Watson 3874
68
568
Harbhajan Singh 829
68
890
CA Lynn 1280
69
1687
DR Smith 2385
70
1508
AC Gilchrist 2069
72
1972
V Sehwag 2728
72
575
ST Jayasuriya 768
74
3630
CH Gayle 4772
76
1194
AD Russell 1517
78
729
SP Narine 892
81
Task:4
Your first priority is to get 2-3 bowlers with good economy who have bowled at least 500
balls in IPL so far.To do that you have to make a list of 10 players you want to bid in the
auction so that when you try to grab them in auction you should not pay the amount
greater than you have in the purse for a particular player.

Solution:
select bowler ,
count(ball) as total_ball ,sum(total_runs) as total_run,
(sum(total_runs)/(count(ball)/6.0)) as economy
from
ipl_ball
group by bowler
having count(ball)>=500
order by economy
limit 10;
OUTPUT TASK:4
TOP 10 ECONOMY BOWLER PLAYER
bowler total_ball total_run economy

Rashid Khan 1490 1573 6.3342

A Kumble 983 1089 6.6470

M Muralitharan 1577 1755 6.6772

DW Steyn 2276 2568 6.7698

R Ashwin 3327 3756 6.7737

SP Narine 2824 3208 6.8159

DL Vettori 785 894 6.8331

Washington Sundar 660 758 6.8909

J Botha 709 818 6.9224

R Tewatia 587 684 6.9915


Economy Rate Of Bowler
7.2

6.8

6.6

6.4

6.2

6
n
bl
e an yn in e ri ar ha a
Kh
a
ar te w ar
i n
tto d o t ati
d u m
il th S
A sh N V e Sun JB ew
shi A
K
ra D W R SP DL on R
T
Ra M
u
ng
t
M h i
as
W
task:5
Now you need to get 2-3 bowlers with the best strike rate and who have bowled at
least 500 balls in IPL so far.To do that you have to make a list of 10 players you want to bid in
the auction so that when you try to grab them in auction you should not pay the amount
greater than you have in the purse for a particular player.

• Solution:
select bowler ,
count(ball) as total_ball ,
sum(is_wicket) as wicket,
(count(ball)/sum(is_wicket)) as strike_rate
from
ipl_ball
group by bowler
having count(ball)>=500
order by strike_rate asc
limit 10;
OUTPUT TASK:5
TOP 10 BEST STRIKE RATE BOWLER
bowler total_ball wicket strike_rate

K Rabada 840 66 12

DE Bollinger 600 43 13

AJ Tye 645 45 14

MA Starc 612 39 15

SL Malinga 2974 188 15

Imran Tahir 1314 83 15

A Nehra 1974 121 16

MM Patel 1382 82 16

DJ Bravo 2846 175 16

KK Cooper 600 36 16
Strike Rate Of Bowler
strike_rate wicket

KK Cooper 16
36
DJ Bravo 16
175
MM Patel 16
82
A Nehra 16
121
Imran Tahir 15
83
SL Malinga 15
188
MA Starc 15
39
AJ Tye 14
45
DE Bollinger 13
43
K Rabada 12
66
Task:6
Now you need to get 2-3 All_rounders with the best batting as well as bowling strike rate and who
have faced at least 500 balls in IPL so far and have bowled minimum 300 particular player.

select
a.bowler AS player, a.total_ball, a.strike_rate as bowler_strikerate, b.strike_rate as
batsman_strikerate
from
(select bowler , count(ball) as total_ball , (count(ball)/sum(is_wicket)) as strike_rate
from ipl_ball
group by bowler having count(ball)>=300 order by strike_rate asc
) as a
inner join
(select batsman, (sum(batsman_runs)*100/ sum(ball)) as strike_rate
from ipl_ball
group by batsman having count(ball)>=500 order by strike_rate desc
)as b
on
a.bowler=b.batsman
limit 10;
OUTPUT TASK:6
TOP 10 BEST ALL ROUNDER PLAYER
Player total_ball bowler_strikerate batsman_strikerate

AD Russell 1186 17 44

SP Narine 2824 19 43

HH Pandya 914 20 40

GJ Maxwell 558 27 40

CH Gayle 584 30 39

KA Pollard 1414 19 38

YK Pathan 1184 25 37

DR Smith 557 20 37

BA Stokes 711 22 37

RG Sharma 342 21 36
All Rounder Player
bowler_strikerate batsman_strikerate

40 39 37
40 38 37 37 36
44 43

27 30 25
20 19 20 22 21
17 19

ell e ya el
l le rd n ith es a
s ir n d a y lla h a k rm
us
Na an a xw G o a t Sm St
o a
R P CH
P P
DR Sh
AD SP HH J M
KA YK BA RG
G
Try to define a criteria best suited for a
wicketkeeper required in a IPL T20

• Best batting as well as bowling strike rate and who have


faced at least 500 balls in IPL so far and have bowled
minimum 300 particular player.
• No of catches he catches.
• Efficient stumping – how many times he stume out batsman .
• Sharp reflexes includes run out.
Additional: 1
Get the count of cities that have hosted an IPL match

Solution:
select city,count(city) as count_of_city from ipl_matches group
by city
order by city;
120
100
80
60
101
40 74 77
65 56 57 64
20 29 47 38
26
12 15 12 9 15 9 8 4 3 5 13 6 10 7 12 13
0 2 7 7 3 3 7
i re i i i re ta ur hi
h ab lo tein r io
n
n na elh
u ba d on o u rg r ley k a NA beth ip n c n am
ga on D d b be ol a
u
D n f n tu
C he D L on In n es m K liz
a R Ra
pa
t
Ab Ba oe
m Ce as
t an Ki rt
E
kh
a
l E h o a
B Jo P Vi
s
Additional: 2
Create table deliveries_v02 with all the columns of the table ‘deliveries’
and an additional column ball_result containing values boundary, dot or
other depending on the total_run (boundary for >= 4, dot for 0 and other
for any other number)
Solution:
create table deliveries_v02 as
select id,inning,over,ball,batsman,non_striker,bowler,batsman_runs,
extra_runs,total_runs,is_wicket,dismissal_kind,player_dismissed,fielder,
extras_type,batting_team,bowling_team,
case
when total_runs =1 then 'single'
when total_runs =2 then 'double'
when total_runs =3 then 'three'
when total_runs >=4 then 'boundary'
else 'dot boll'
end as ball_result
from ipl_ball
Additional: 3
Write a query to fetch the total number of boundaries and dot balls from
the deliveries_v02 table.

Solution:
select ball_result,count(ball_result) from deliveries_v02
group by ball_result
having ball_result='boundary' or ball_result= 'dot boll‘

Output:

“boundary" 31468
"dot boll" 67841
Additional:4
Write a query to fetch the total number of boundaries scored by each
team from the deliveries_v02 table and order it in descending order of
the number of boundaries scored.

Solution:
select batting_team,count(ball_result)as total_boundaries
from deliveries_v02
group by batting_team,ball_result
having ball_result='boundary'
order by count(ball_result) desc
Output:4
Boundaries scored by each team
batting_team total_boundaries
Mumbai Indians 4118
Royal Challengers Bangalore 3800
Kings XI Punjab 3780
Kolkata Knight Riders 3739
Chennai Super Kings 3496
Rajasthan Royals 3041
Delhi Daredevils 3022
Sunrisers Hyderabad 2306
Deccan Chargers 1387
Pune Warriors 733
Delhi Capitals 659
Gujarat Lions 624
Rising Pune Supergiant 290
Rising Pune Supergiants 242
Kochi Tuskers Kerala 231
Additional: 5
Write a query to fetch the total number of dot balls bowled by each
team and order it in descending order of the total number of dot balls
bowled.

Solution:
select bowling_team,count(ball_result)as total_dot_ball from
deliveries_v02
group by bowling_team,ball_result
having ball_result='dot boll'
order by count(ball_result) desc;
Output:5
Dot balls bowled by each team
bowling_team total_dot_ball
Mumbai Indians 8714
Royal Challengers Bangalore 7955
Kolkata Knight Riders 7894
Kings XI Punjab 7679
Chennai Super Kings 7593
Rajasthan Royals 6665
Delhi Daredevils 6520
Sunrisers Hyderabad 5248
Deccan Chargers 3306
Pune Warriors 1900
Delhi Capitals 1338
Gujarat Lions 1095
Rising Pune Supergiant 698
Kochi Tuskers Kerala 626
Rising Pune Supergiants 539
Na 71
Dot ball and boundaries by each team
14000

12000

10000

8000

6000
total_boundaries
Axis Title 4000 total_dot_ball

2000

0
ns rs s s rs tals t ts
i a e ng vi l e i an n
n d R
d
i r Ki d e arg api rg rgia
iI e pe pe
a g ht upe Dar n Ch hi C u
m
b
Kni i S
l h i
cc a
D e l e
S
e
Su
u a e n
M kata enn D D e Pu
P u n
o l h n g g
C i
K
Ri
s i sin
R
Additional:6
Write a query to fetch the total number of dismissals by dismissal kinds
where dismissal kind is not NA
Solution:
select dismissal_kind,count (dismissal_kind) from deliveries
where dismissal_kind!='NA'
group by dismissal_kind;

bowled 1700
caught 5743
caught and bowled 269
hit wicket 12
lbw 571
obstructing the field 2
retired hurt 11
run out 893
stumped 294
total number of dismissals by dismissal kinds
stumped
3%
retired hurt
0%
obstructing run out bowled
thewicket
hit field 9% 18%
0%
0% lbw
6%
caught and
bowled
3%

caught
60%
Additional: 7
Write a query to get the top 5 bowlers who conceded maximum extra
runs from the deliveries_v02 table

Solution:
select bowler,
sum(extra_runs) as sum_of_extra_run from deliveries_v02
group by bowler
order by sum(extra_runs) desc
limit 5;
Output:7
Top 5 bowlers who conceded maximum extra runs
sum_of_extra_run
sum_of_extra_ru sum_of_extra_run
bowler n
293
SL Malinga 293
236 226
210 201
P Kumar 236

UT Yadav 226

DJ Bravo 210

B Kumar 201 SL Ma- P Kumar UT DJ Bravo B Kumar


linga Yadav
Additional :8
Write a query to create a table named deliveries_v03 with all the
columns of deliveries_v02 table and two additional column (named
venue and match_date) of venue and date from table matches

Solution :
create table deliveries_v03 as (
select
a.*, b.venue,b.date as match_date
from
ipl_ball as a
left join
ipl_matches as b
on
a.id=b.id);
Additional :9
Write a query to fetch the total runs scored for each venue and order it
in the descending order of total runs scored.

Solution:
select venue,sum(total_runs) as venue_total_run
from deliveries_v03
group by venue
order by sum(total_runs) desc;
Addtional:10
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.

Solution:
select venue,sum(total_runs) as total_run,
(extract (year from match_date))as year from deliveries_v03
where venue= 'Eden Gardens'
group by venue,(extract (year from match_date))
order by sum(total_runs) desc
Output:10
year-wise total runs scored at Eden Gardens
venue total_run year
Eden Gardens 2885 2018

Eden Gardens 2651 2019

Eden Gardens 2386 2015


Eden Gardens 2304 2013

Eden Gardens 2194 2017

Eden Gardens 2167 2010

Eden Gardens 2073 2016

Eden Gardens 2012 2012


Eden Gardens 1854 2011

Eden Gardens 1843 2008

Eden Gardens 1289 2014


Total runs scored at Eden Gardens

3500

3000

2500

2000

1500

1000

500

0
2018 2019 2015 2013 2017 2010 2016 2012 2011 2008 2014

You might also like