Public
Edited
Sep 4, 2023
1 fork
Insert cell
Insert cell
Insert cell
db = DuckDBClient.of({
batting:battingFile,
people:peopleFile,
teams:teamsFile
})
Insert cell
db
ALTER TABLE batting
ALTER yearID TYPE USMALLINT
Insert cell
db
ALTER TABLE teams
ALTER yearID TYPE USMALLINT
Insert cell
db
DESCRIBE teams
Insert cell
Insert cell
db
SELECT nameFirst,nameLast,batting.playerID,REPLACE(yearID,',',''),teamID,HR
FROM batting INNER JOIN people
ON batting.playerID = people.playerID
WHERE HR >= 50
ORDER BY HR DESC
Insert cell
db
SELECT max(nameFirst) AS firstName,max(nameLast) AS lastName,batting.playerID,REPLACE(yearID,',',''),sum(HR) AS seasonHR
FROM batting INNER JOIN people
ON batting.playerID = people.playerID
GROUP BY batting.playerID, yearID
HAVING seasonHR >= 50
ORDER BY seasonHR DESC
Insert cell
db
SELECT max(nameFirst) AS firstName,max(nameLast) AS lastName,batting.playerID,sum(HR) as careerHR
FROM batting INNER JOIN people
ON batting.playerID = people.playerID
GROUP BY batting.playerID
HAVING careerHR >= 500
ORDER BY careerHR DESC
Insert cell
Insert cell
db
SELECT playerID,batting.teamID,name,REPLACE(batting.yearID,',',''),batting.HR
FROM batting INNER JOIN teams
ON batting.teamID = teams.teamID AND batting.yearID = teams.yearID
WHERE playerID = 'ruthba01'
Insert cell
Insert cell
db
SELECT max(nameFirst) AS firstName,max(nameLast) AS lastName,batting.playerID,sum(batting.HR) AS seasonHR,
IF(max(name) == min(name),max(name),CONCAT(min(name),'/',max(name))) AS team,
REPLACE(batting.yearID,',','') AS season
FROM (batting INNER JOIN people
ON batting.playerID = people.playerID)
INNER JOIN teams
ON batting.teamID = teams.teamID AND batting.yearID = teams.yearID
GROUP BY batting.playerID,batting.yearID
HAVING seasonHR >= 50
ORDER BY seasonHR DESC
Insert cell
Insert cell
db
SELECT max(name) AS teamName
FROM teams
GROUP BY name
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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