Published
Edited
Jul 25, 2021
8 stars
Insert cell
Insert cell
Insert cell
events = dc.query(`
SELECT *
FROM events
ORDER BY time
`)
Insert cell
Table(events)
Insert cell
Insert cell
cohorts = dc.query(`
WITH signups AS (
SELECT user_id, DATE(time) AS cohort_date
FROM events
WHERE type = 'signup'
GROUP BY 1, 2
)
SELECT cohort_date, DATE(time) AS period_date, COUNT(DISTINCT e.user_id) as users
FROM events e INNER JOIN signups s ON e.user_id = s.user_id
GROUP BY 1, 2
ORDER BY 1, 2
`)
Insert cell
Table(cohorts)
Insert cell
Insert cell
import {SQLiteDatabaseClient} from "@mbostock/sqlite@259"
Insert cell
import {Table} from "@observablehq/inputs"
Insert cell
function ExampleDatabase() {
const file = FileAttachment("events.db");
return Object.defineProperties(new SQLiteDatabaseClient(file.arrayBuffer()), {
name: {value: "events", enumerable: true}
});
}
Insert cell
dc = ExampleDatabase()
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