harsha547
12/17/2016 - 6:16 PM

Matches won by chasing and first_batting

Matches won by chasing and first_batting


-- Examples Queries to run on Indian Premier League Database.

-- Matches won by chasing and first_batting  

SELECT Team_Name , 
       SUM( CASE WHEN Toss_Name = 'field' THEN 1 ELSE 0 END ) AS "Chasing",
       SUM( CASE WHEN Toss_Name = 'bat' THEN 1 ELSE 0 END ) AS "First_Batting"
FROM 
     Match
INNER JOIN
     Toss_Decision
ON   
     Match.Toss_Decide = Toss_Decision.Toss_Id
INNER JOIN
     Team
ON 
     Match.Match_Winner = Team.Team_Id
GROUP BY GROUPING SETS ( Team_Name, ())