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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more