Public
Edited
Jun 7, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pizzeriaDB
SELECT row_number() over (partition by Category order by Launch) as "Row Number", *
FROM products
Insert cell
Insert cell
pizzeriaDB
SELECT products.name
, products.size
, products.category
, count(distinct orders.id) as "Number of Orders"
, rank() over (partition by products.category order by count(distinct orders.id) DESC) as "Order Rank"
FROM products
JOIN order_items
ON products.SKU = order_items.SKU
JOIN orders
ON order_items.orderId = orders.id
GROUP BY 1, 2, 3
Insert cell
Insert cell
pizzeriaDB
SELECT products.name
, products.size
, products.category
, date_part('year', orders.orderDate::date)::string as year_name
, row_number() over (partition by year_name order by orderDate asc) as row_num
FROM products
JOIN order_items
ON products.SKU = order_items.SKU
JOIN orders
ON order_items.orderId = orders.id
ORDER BY row_num, year_name
LIMIT 3
Insert cell
Insert cell
pizzeriaDB
WITH utahStores AS (
SELECT *
FROM stores
WHERE state = 'Utah'
)

SELECT date_trunc('month', orders.orderDate::date) as "Month Name"
, count(distinct orders.id) as "Number of Orders"
FROM orders
JOIN utahStores
ON orders.storeId = utahStores.id
GROUP BY 1
Insert cell
Insert cell
pizzeriaDB
Type SQL, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
pizzeriaDB
WITH newData AS (
SELECT orders.id
, products.*
FROM orders
LEFT
JOIN order_items
ON orders.id = order_items.orderId
LEFT
JOIN products
ON order_items.SKU = products.SKU
)

SELECT DISTINCT name
, Size
, count(distinct id)
FROM newData
WHERE Category = 'Vegetarian'
GROUP BY 1, 2
Insert cell
pizzeriaDB
Type SQL, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
groceries
SELECT avg(amount) as avg_amount
FROM groceries
WHERE category = 'Fruits'
Insert cell
Insert cell
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