Busabase
Busabase는 AI 에이전트를 위한 오픈소스(MIT) 데이터베이스 및 작업 공간입니다
Retail SQL Analytics: DuckDB-WASM으로 브라우저에서 100만 건 소매 데이터 분석
Ten SQL analyses of one million real online-retail sales lines (cohorts, RFM, Lorenz curve, market basket), run live in your browser with DuckDB-WASM.
데이터JavaScript · CSSGitHub @Z3US-23온라인운영자 미확인
써 보셨어요? 한 번만 눌러 주세요. 로그인은 필요 없어요.
아직 감지된 업데이트가 없습니다. GitHub 릴리스가 나오면 여기에 보입니다.
개인 계정의 공개 저장소 소유자는 GitHub로 로그인해 운영자를 확인하고 소개를 직접 관리할 수 있습니다. 관리자 승인은 필요하지 않습니다.
로그인한 뒤 확인 파일을 만들어 이 저장소의 기본 브랜치에 30분 안에 커밋해 주세요. 다른 브랜치나 포크의 파일은 인정하지 않습니다. 파일을 올린 뒤 아래에서 확인하면 관리자 승인 없이 관리할 수 있습니다. 자격을 유지하려면 파일을 남겨 두세요.
로그인이 필요하면 로그인 화면으로 이동합니다. 로그인 후 이곳으로 돌아와 원하는 확인 버튼을 다시 눌러 주세요.
프로젝트 폴더에서 /nomorevibe verify를 실행하면 소유권을 확인하고 소개를 직접 관리할 수 있습니다.
1분 만에 확인하기10 SQL analyses of 1M real retail sales lines (cohorts, RFM, Lorenz/Gini, market basket), run live in the browser with DuckDB-WASM
저장소 README에서 가져옴
README 전체를 불러오는 중입니다. 아래는 저장된 발췌입니다.
Ten SQL analyses of one million real online-retail sales lines, run live in your browser.
The data is two years of transactions (Dec 2009 – Dec 2011) from a UK online gift wholesaler.
I cleaned it with SQL, then wrote ten SQL queries that each answer one business question.
The dashboard has no server. DuckDB-WASM runs a
real SQL database inside the browser tab, so:README 전문 보기 ↗Ten SQL analyses of one million real online-retail sales lines, run live in your browser.
The data is two years of transactions (Dec 2009 – Dec 2011) from a UK online gift retailer (many of its customers are wholesalers). I cleaned it with SQL, then wrote ten SQL queries that each answer one business question.
The dashboard has no server. DuckDB-WASM runs a real SQL database inside the browser tab, so:
The same .sql files run in the browser and in a Python test on GitHub Actions, so the code you
read here is exactly the code that drew the charts.
| # | Question | SQL techniques | Finding (full period) |
|---|---|---|---|
| 01 | How big is the business? | FILTER clauses, COUNT DISTINCT | £18.9M net revenue, 39,516 orders, 5,875 customers, £497 per order |
| 02 | Is it growing, and how seasonal is it? | CTEs, date_trunc, self-join on dates | Every autumn builds to a November peak (£1.43M in Nov 2011, +2.3% on Nov 2010) |
| 03 | Which markets matter? | window functions over aggregates, RANK | UK = 85% of revenue, but overseas orders are bigger (£853 vs £464) |
| 04 | Which products earn the most? | aggregate first, then join | The cake stand earns most, even though the jumbo bag sells 3.8× more units |
| 05 | How unequal is spending? | running totals, Gini coefficient in SQL | Top 20% of customers → 77% of revenue; Gini = 0.74 |
| 06 | Who are the best customers, and who is leaving? | NTILE scoring, CASE rules (RFM) | "Champions" are 25% of customers but 70% of revenue; 350 big buyers have gone quiet |
| 07 | Do new customers come back? | cohort analysis, datediff, FIRST_VALUE | Only ~21% re-order the next month; lapsed customers return each November |
| 08 | What is bought together? | self-join, support / confidence / lift | Matching teacups are bought together 21× more often than chance |
| 09 | When do people order? | date parts, heatmap grid | 67% of orders arrive 10:00–15:00; almost none on Saturdays (a B2B business) |
| 10 | What gets returned? | conditional aggregation, thresholds | The worst "return rate" is one 74,215-jar order cancelled 16 minutes later |
The raw Excel file has 1,067,371 rows. etl/clean.sql fixes four problems I
found by exploring the data first:
| Step | Rows removed | Why |
|---|---|---|
| Sheet overlap | 22,523 | The 2009–10 sheet runs to 9 Dec 2010, but the 2010–11 sheet starts on 1 Dec 2010 and repeats those rows exactly |
| Non-product lines | 11,930 | Postage, bank charges, Amazon fees, manual adjustments, test items, zero prices and stock write-offs are not sales of goods |
| Exact duplicates | 11,792 | The same line scanned twice (same invoice, product, quantity, price, time) |
| Clean sales lines | 1,021,126 |
Cancelled orders (invoice numbers starting with C) are kept as negative lines so returns can be
analysed. About 22% of lines have no customer ID; they count towards revenue but are left out of
the customer analyses (05–07).
Excel (UCI) ──► etl/build_data.py ──► etl/clean.sql (DuckDB) ──► data/*.parquet (5.4 MB)
│
browser: DuckDB-WASM loads the Parquet ◄───────┘
filters rewrite one SQL view: `sales`
sql/01–10 run against it ──► ECharts
CREATE OR REPLACE VIEW sales AS SELECT … WHERE …), and
every query reads from sales. Click Filter SQL on the dashboard to see it.etl/run_queries.py runs all ten queries in Python with the same setup.
GitHub Actions runs it on every push, so a broken query fails the build.├── index.html the dashboard page
├── assets/ app.js (DuckDB + filters + playground), charts.js, util.js, app.css
├── sql/ the ten analysis queries (the main work)
├── etl/
│ ├── build_data.py download → load → clean → export Parquet
│ ├── clean.sql all cleaning rules, commented
│ └── run_queries.py runs every query (also the CI test)
└── data/ sales.parquet, products.parquet, cleaning_report.json
git clone https://github.com/Z3US-23/retail-sql-analytics.git
cd retail-sql-analytics
python -m venv .venv
.venv\Scripts\activate # Windows (macOS/Linux: source .venv/bin/activate)
pip install -r requirements.txt
python etl/run_queries.py # run all ten queries in the terminal
python -m http.server 8000 # then open http://localhost:8000
To rebuild the data from the original Excel file: python etl/build_data.py (downloads 45 MB).
Chen, D. (2012). Online Retail II [Data set]. UCI Machine Learning Repository. https://doi.org/10.24432/C5CG6D, licensed CC BY 4.0. Prices are in GBP.
Built by Ahmad Ammar, BS Economics, Forman Christian College, Lahore · Tools: SQL (DuckDB), Python, JavaScript, Apache ECharts.