Public
Edited
Nov 21, 2023
20 forks
Insert cell
Insert cell
Insert cell
Insert cell
db = DuckDBClient.of({
batting:batting,
people:people
})
Insert cell
Insert cell
db
SELECT playerID, yearID, teamID, 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,yearID,teamID,HR,max(HR) OVER(partition by teamID) AS max
FROM batting
WHERE yearID = 2022
ORDER BY teamID
Insert cell
db
SELECT playerID,yearID,teamID,HR,max(HR) OVER(partition by teamID,yearID) AS max
FROM batting
ORDER BY teamID,yearID
Insert cell
db
SELECT playerID,teamID,yearID,HR,row_number() OVER()
FROM batting
Insert cell
db
SELECT playerID,teamID,yearID,HR,rank() OVER(order by HR DESC)
FROM batting
Insert cell
db
SELECT playerID,teamID,yearID,HR, rank() OVER(partition by teamID order by HR DESC) AS rank
FROM batting
WHERE yearID = 2022
ORDER BY teamID,rank
Insert cell
db
SELECT playerID,teamID,yearID,HR,100*HR/sum(HR) OVER(partition by teamID)
FROM batting
WHERE yearID = 2022
ORDER BY teamID
Insert cell
db
SELECT playerID,teamID,yearID,HR,sum(HR) OVER(rows unbounded preceding)
FROM batting
WHERE playerID = 'ruthba01'
Insert cell
db
SELECT playerID,teamID,yearID,HR,avg(HR) OVER(rows between 2 preceding and 2 following)
FROM batting
WHERE playerID = 'ruthba01'
Insert cell
db
SELECT playerID,teamID,yearID,HR,lag(HR,1) OVER()
FROM batting
WHERE playerID = 'ruthba01'
Insert cell
db
SELECT playerID,teamID,yearID,HR,HR - lag(HR,1) OVER()
FROM batting
WHERE playerID = 'ruthba01'
Insert cell
db
SELECT playerID,teamID,yearID,HR,100*(HR - lag(HR,1) OVER())/(lag(HR,1) 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