Public
Edited
Apr 29, 2023
Fork of SQL + Chart
3 forks
Importers
Insert cell
Insert cell
Plot.plot({
x:{
tickFormat: "d"
},
y:{
label: "Average Margin of victory (Seconds)"
},
marginLeft: 50,
marks: [
Plot.ruleY([0]),
Plot.line(df, {x: "year", y: "avg_margin_of_victory"}),
Plot.dot(df, {x: "year", y: "avg_margin_of_victory", fill: "black",
title: (d) => // tooltip function
`${d.year} \n Champion: ${d.driver_champion} \n Avg Margin of Victory: ${d3.format(".2f")(d.avg_margin_of_victory)} seconds`})
]
})
Insert cell
database = FileAttachment("f1_db@1.sqlite").sqlite()
Insert cell
database
SELECT races.year,
AVG(results2.time - results1.time) AS avg_margin_of_victory
FROM races
JOIN results AS results1 ON races.raceId = results1.raceId AND results1.position = 1
JOIN results AS results2 ON races.raceId = results2.raceId AND results2.position = 2
GROUP BY races.year;





Insert cell
import {Plot} from "@mkfreeman/plot-tooltip"
Insert cell
database
SELECT year, surname AS driver_champion
FROM (
SELECT DISTINCT races.year, driver_standings.points, drivers.surname,
RANK() OVER (PARTITION BY races.year ORDER BY driver_standings.points DESC) AS rank
FROM races
JOIN driver_standings ON races.raceId = driver_standings.raceId AND driver_standings.position = 1
JOIN drivers ON driver_standings.driverId = drivers.driverId
)
WHERE rank = 1 AND year < 2023
ORDER BY year;

Insert cell
df = aq.from(query)
.join_left(aq.from(champs), 'year')
Insert cell
import {op, aq} from "@uwdata/arquero"
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