Public
Edited
Nov 13, 2023
Insert cell
Insert cell
batting = FileAttachment("Batting.csv").csv({typed:true})
Insert cell
db = DuckDBClient.of({
batting:batting
})
Insert cell
db
SELECT playerID,teamID,yearID,HR,max(HR) OVER()
FROM batting
Insert cell
db
SELECT playerID,sum(HR) as careerHR,max(careerHR) OVER()
FROM batting
GROUP BY playerID

Insert cell
db
SELECT playerID, teamID, yearID,HR,max(HR) OVER(partition by teamID,yearID)
FROM batting
ORDER BY teamID,yearID

Insert cell
db
SELECT playerID,yearID,teamID,HR,rank() OVER(order by HR DESC)
FROM batting
Insert cell
db
SELECT playerID,sum(HR) as careerHR,rank() OVER(order by careerHR DESC)
from batting
group by playerID
Insert cell
db
SELECT playerID,teamID,yearID,HR,rank() OVER(partition by teamID order by HR DESC)
FROM batting
WHERE yearID = 2022
Insert cell
db
SELECT playerID,teamID,yearID,HR,rank
FROM
(SELECT playerID,teamID,yearID,HR,rank() OVER(partition by teamID order by HR DESC) AS rank
FROM batting
WHERE yearID = 2022)
WHERE rank <= 10
Insert cell
db
SELECT playerID,teamID,yearID,HR,100*HR/sum(HR) OVER(partition by teamID) as percen
FROM batting
WHERE yearID = 2022
ORDER BY teamID,percen DESC

Insert cell
db
SELECT playerID,yearID,teamID,HR,sum(HR) OVER(rows unbounded preceding)
FROM batting
WHERE playerID = 'ruthba01'
Insert cell
db
SELECT playerID,yearID,teamID,HR,sum(HR) OVER(rows between 2 preceding and 2 following)
FROM batting
WHERE playerID = 'ruthba01'
Insert cell
db
SELECT playerID,yearID,teamID,HR,lag(HR,2) OVER()
FROM batting
WHERE playerID = 'ruthba01'
Insert cell
db
SELECT playerID,yearID,teamID,HR,100*(HR - lag(HR) OVER())/(lag(HR) OVER ())
from batting
WHERE playerID = 'ruthba01'
Insert cell
db
SELECT playerID,group_concat(DISTINCT teamID)
FROM batting
WHERE playerID = 'ruthba01'
GROUP BY playerID
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more