Skip to content

Instantly share code, notes, and snippets.

@harsha547
Created April 16, 2017 15:18
Show Gist options
  • Save harsha547/cca72ebd90f9eb262597cf7676fbf04c to your computer and use it in GitHub Desktop.
Save harsha547/cca72ebd90f9eb262597cf7676fbf04c to your computer and use it in GitHub Desktop.
Players with most Centuries in IPL ( 2008 - 2016 )
-- Players with most Centuries in IPL ( 2008 - 2016 )
WITH CTE ( Match_Id , Player_Name , Runs )
As
(
SELECT A.Match_Id , C.Player_Name , SUM(B.Runs_Scored) As 'Runs'
FROM Ball_by_Ball A
INNER JOIN Batsman_Scored B
ON CONCAT(A.Match_Id,A.Over_Id,A.Ball_Id,A.Innings_No)
= CONCAT(B.Match_Id,B.Over_Id ,B.Ball_Id ,B.Innings_No)
INNER JOIN Player C
ON A.Striker = C.Player_Id
GROUP BY A.Match_Id , C.Player_Name
HAVING SUM(B.Runs_Scored) >= 100
)
SELECT Player_Name , COUNT(*) As 'Centuries'
FROM CTE
GROUP BY Player_Name
ORDER BY Centuries DESC
@harsha547
Copy link
Author

Solution 👍

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment