Public
Edited
Oct 26, 2023
1 fork
Insert cell
Insert cell
batting = FileAttachment("Batting.csv").csv({typed:true})
Insert cell
people = FileAttachment("People.csv").csv({typed:true})
Insert cell
db = DuckDBClient.of({
batting:batting,
people:people
})
Insert cell
db
CREATE VIEW classData
(nameFirst,nameLast,playerID,teamID,yearID,HR)
AS
SELECT
nameFirst,nameLast,batting.playerID,teamID,yearID,HR
FROM batting INNER JOIN people
ON batting.playerID = people.playerID
Insert cell
db
DESCRIBE classData
Insert cell
db
SELECT playerID, teamID, yearID, HR, max(HR) OVER (partition by teamID,yearID)
FROM batting
WHERE yearID > 1970 AND teamID = 'PHI'
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
FROM
(SELECT playerID,teamID,yearID,HR, rank() OVER (partition by teamID order by HR DESC) rank
FROM batting
WHERE yearID = 2022
ORDER BY teamID,rank)
WHERE rank <= 10
Insert cell
db
SELECT playerID,teamID,yearID,HR,HR/sum(HR) OVER (partition by teamID) AS percent
FROM batting
where yearID = 2022
ORDER BY teamID,percent DESC
Insert cell
db
SELECT playerID,yearID,HR,sum(HR) OVER (rows unbounded preceding)
FROM batting
WHERE playerID = 'ruthba01'
ORDER BY yearID
Insert cell
db
SELECT playerID,yearID,HR,avg(HR) OVER (rows between 1 preceding and 1 following)
FROM batting
WHERE playerID = 'ruthba01'
ORDER BY yearID
Insert cell
28/2
Insert cell
db
SELECT playerID,yearID,HR,(HR - lag(HR,1) OVER ())/lag(HR,1) OVER (),
FROM batting
WHERE playerID = 'ruthba01'
ORDER BY yearID
Insert cell
9/2
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