Public
Edited
Apr 4, 2023
6 forks
Importers
24 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
db
with purchased_items as (
SELECT * FROM events
JOIN items ON events.item_id = items.id
WHERE type = 'purchase'
)
select
name,
count(*)::INT as count,
sum(price_in_usd)::INT as revenue,
FIRST(category) as category
from purchased_items
group by name, category
order by count desc
Insert cell
Insert cell
data = getFiltered(search, items, links)
Insert cell
data2 = getFiltered([search2], items, links)
Insert cell
function getFiltered(search, items, links) {
const searchedLinks = links.filter(l => search.find(d => d?.name === l.item_a || d?.name === l.item_b))
const searchedItems = items.filter(d => searchedLinks.find(l => d.name === l.item_a || d.name === l.item_b))
return {
nodes: searchedItems,
links: searchedLinks
}
}
Insert cell
dateFormat = d3.utcFormat("%Y-%m-%d")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
notebooks = [
{
title: "Which items are purchased together?",
path:
"@observablehq/which-items-are-purchased-together",
thumbnail: "b39e834adfbe703df48916786d9a9bfef04dc0100c3b684a44db43878c28b266"
},
{
title: "Part 1: Co-occurrence SQL query",
path:
"@observablehq/arsc-part-1-co-occurrence-sql-query",
thumbnail: "5fb57905caca18de4511d89f9ec6b3dfb8dfa6c6b38f62d2798e7cb7e9b4c4e2"
},
{
title: "Part 2: Interactive filtering",
path:
"@observablehq/arsc-part-2-interactive-filtering",
thumbnail: "7bb7f01497112ba5c08237ffeea20ccc87dbbc03b646afc9ffb32a3e38c024ef"
},
{
title: "Part 3: Matrix visualization",
path:
"@observablehq/arsc-part-3-matrix-visualization",
thumbnail: "6788484f6814389c2ccdab1a2a00f0ddffdb3f88bc5e870a5d6a3194631a2c61"
},
{
title: "Part 4: Force layout visualization",
path:
"@observablehq/arsc-part-4-force-layout-visualization",
thumbnail: "915226635db14cbb92290d78ef53a37c834437861a1e124cbfeb1d6385d8e11b"
},
].map(d => ({...d, collection: collection.path}))
Insert cell
Insert cell
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