1. Lighthouse

Level 4 · Pareto: do 20% of products make 80% of sales?

The request

From Thomas Whitaker, Head of Merchandising

“A consultant told us '80% of your sales come from 20% of your products, cut the long tail'. Before I cut anything, can you check it on our real numbers from 2023 to 2025?”

Your goal

The starter's product_sales CTE has product_id and net_sales (net sales of valid lines on booked orders, 2023 to 2025) for every product that sold. Return sales_rank (1 = highest net_sales; break ties by product_id), product_id, net_sales (rounded to 2) and cum_share_pct (the running total of net_sales up to and including this product × 100 / all net_sales, rounded to 2), one row per product, sorted by sales_rank.

  • Read from the orders tablenot done yet
  • Read from the order_items tablenot done yet
  • Show exactly sales_rank product_id net_sales cum_share_pctnot done yet
Cumulative share of net sales, products ranked from best seller
Cumulative share of net sales, products ranked from best seller0%20%40%60%80%100%cum_share110192837465564738291100109118Products, ranked by net salesCumulative share of net sales
Cumulative share of net sales, products ranked from best seller0%20%40%60%80%100%cum_share11937557391109Products, ranked by net salesCumulative share of net sales

A strict 80/20 store would reach 80% at product 24. Harbor & Pine reaches it at product 56.

Show the numbers
Products, ranked by net salesCumulative share of net sales
16.7%
211%
314.6%
418.1%
520.8%
623.5%
725.9%
828.2%
930.4%
1032.4%
1134.4%
1236.3%
1338%
1439.8%
1541.4%
1643%
1744.5%
1845.9%
1947.3%
2048.7%
2150.1%
2251.4%
2352.6%
2453.7%
2554.9%
2656.1%
2757.2%
2858.3%
2959.4%
3060.5%
3161.5%
3262.6%
3363.6%
3464.6%
3565.6%
3666.5%
3767.3%
3868.1%
3968.9%
4069.6%
4170.4%
4271.2%
4371.9%
4472.7%
4573.4%
4674.1%
4774.8%
4875.5%
4976.2%
5076.8%
5177.5%
5278.1%
5378.7%
5479.3%
5579.9%
5680.5%
5781.1%
5881.7%
5982.2%
6082.8%
6183.4%
6283.9%
6384.5%
6485.1%
6585.6%
6686.1%
6786.6%
6887.1%
6987.6%
7088.1%
7188.6%
7289.1%
7389.6%
7490%
7590.4%
7690.9%
7791.2%
7891.6%
7992%
8092.3%
8192.7%
8293%
8393.3%
8493.6%
8593.9%
8694.2%
8794.5%
8894.8%
8995%
9095.3%
9195.5%
9295.8%
9396%
9496.3%
9596.5%
9696.7%
9796.9%
9897.1%
9997.3%
10097.5%
10197.7%
10297.9%
10398.1%
10498.3%
10598.5%
10698.6%
10798.8%
10898.9%
10999%
11099.1%
11199.2%
11299.4%
11399.5%
11499.6%
11599.7%
11699.8%
11799.8%
11899.9%
119100%
120100%

Your query

SQL

Loading the editor…

    ResultPreview of orders · press Run to see yours
    Preview of orders
    order_idcustomer_idorder_datestatuschannel
    10011252023-01-01 20:51:19completedweb
    10021562023-01-02 07:58:46completedweb
    1003222023-01-02 10:25:27completedmarketplace
    1004482023-01-02 11:21:51completedmarketplace

    Mote checks your result

    Press Run. Each row that matches the goal becomes a firefly in your lantern.

    Tables

    Harbor & Pine store data, ready to query.

    orders12,000 rows · 7 columns
    • order_idinteger
    • customer_idinteger
    • order_datetimestamp
    • statusvarchar
    • channelvarchar
    • shipping_feedecimal
    • coupon_codevarchar
    First 5 rows of orders
    order_idcustomer_idorder_datestatuschannelshipping_feecoupon_code
    10011252023-01-01 20:51:19completedweb0.00NULL
    10021562023-01-02 07:58:46completedweb0.00NULL
    1003222023-01-02 10:25:27completedmarketplace4.99WELCOME10
    1004482023-01-02 11:21:51completedmarketplace4.99WELCOME10
    1005822023-01-02 11:43:36completedweb0.00WELCOME10
    order_items30,338 rows · 6 columns
    • order_item_idinteger
    • order_idinteger
    • product_idinteger
    • quantityinteger
    • unit_pricedecimal
    • discount_pctdecimal
    First 5 rows of order_items
    order_item_idorder_idproduct_idquantityunit_pricediscount_pct
    11001121931.990.00
    21001154311.990.00
    31002154411.990.00
    410021941149.000.00
    51002193219.990.00
    customers2,018 rows · 9 columns
    • customer_idinteger
    • first_namevarchar
    • last_namevarchar
    • emailvarchar
    • cityvarchar
    • statevarchar
    • signup_datedate
    • segmentvarchar
    • referral_sourcevarchar
    First 5 rows of customers
    customer_idfirst_namelast_nameemailcitystatesignup_datesegmentreferral_source
    1OwenHudsonowen.hudson@icloud.comSan FranciscoCA2022-06-02consumersearch
    2DouglasMendozadmendoza69@gmail.comAtlantaGA2022-06-02consumerNULL
    3HenryBrookshbrooks@lakesidecafe.comLos AngelesCA2022-06-04businessNULL
    4BrianGrahambgraham@bluecedarhomes.comSeattleWA2022-06-06businesspinterest
    5KyleJimenezkjimenez27@yahoo.comIndianapolisIN2022-06-07consumerNULL
    products120 rows · 8 columns
    • product_idinteger
    • namevarchar
    • categoryvarchar
    • subcategoryvarchar
    • unit_pricedecimal
    • unit_costdecimal
    • launched_ondate
    • is_activeboolean
    First 5 rows of products
    product_idnamecategorysubcategoryunit_priceunit_costlaunched_onis_active
    101Vale Velvet LoveseatFurnitureSofas1659.00NULL2023-09-11true
    102Alder Oak Coffee TableFurnitureTables919.00503.502024-05-16true
    103Orchard Rattan Dining ChairFurnitureChairs789.00429.872023-05-27true
    104Upland Oak BookcaseFurnitureStorage429.00214.702022-12-20true
    105Avery Leather Bed FrameFurnitureBeds449.00232.702021-08-31true
    returns1,673 rows · 5 columns
    • return_idinteger
    • order_item_idinteger
    • returned_ondate
    • reasonvarchar
    • refund_amountdecimal
    First 5 rows of returns
    return_idorder_item_idreturned_onreasonrefund_amount
    1142023-01-10damaged83.69
    2422023-01-10wrong_item19.99
    31052023-01-14wrong_item10.99
    4242023-01-16changed_mind26.99
    51262023-01-16late20.99
    employees60 rows · 8 columns
    • employee_idinteger
    • first_namevarchar
    • last_namevarchar
    • departmentvarchar
    • titlevarchar
    • manager_idinteger
    • hire_datedate
    • salaryinteger
    First 5 rows of employees
    employee_idfirst_namelast_namedepartmenttitlemanager_idhire_datesalary
    1CatherineHaleExecutiveChief Executive OfficerNULL2016-03-01285000
    2RobertKimExecutiveChief Operating Officer12017-01-09235000
    3MeganCollinsSalesHead of Sales12018-04-16172000
    4ChloeGutierrezSalesAccount Executive32020-01-2172000
    5FrankBellSalesAccount Executive32023-05-2173000
    web_sessions40,000 rows · 7 columns
    • session_idinteger
    • customer_idinteger
    • started_attimestamp
    • devicevarchar
    • sourcevarchar
    • pages_viewedinteger
    • convertedboolean
    First 5 rows of web_sessions
    session_idcustomer_idstarted_atdevicesourcepages_viewedconverted
    1NULL2023-01-01 23:02:24mobilepaid1false
    2182023-01-01 15:07:49desktoppaid1false
    3NULL2023-01-01 16:55:46desktopdirect7false
    4NULL2023-01-01 12:43:28mobileorganic3false
    5NULL2023-01-01 13:06:21mobilesocial2false
    marketing_spend3,276 rows · 3 columns
    • spend_datedate
    • channelvarchar
    • amountdecimal
    First 5 rows of marketing_spend
    spend_datechannelamount
    2023-01-01paid492.99
    2023-01-01email37.38
    2023-01-01social200.53
    2023-01-02paid709.13
    2023-01-02email64.13

    The lesson

    The 80/20 rule is a claim, not a law

    The Pareto principle says a small share of causes makes a large share of results: 20% of products, 80% of sales. It is often roughly true, and often quoted without checking. The check is simple and every analyst should be able to run it in a few lines: rank the products, add up their sales from the top, and see where the running total crosses 80%.

    Running totals with window functions

    A window function computes over a set of rows without collapsing them. With an ORDER BY inside OVER, SUM becomes a running total:

    SUM(net_sales) OVER (ORDER BY net_sales DESC, product_id)   -- up to this row
    SUM(net_sales) OVER ()                                       -- all rows

    Divide the first by the second and you have the cumulative share. ROW_NUMBER() with the same ordering gives each product its rank.

    Ties need a tie-breaker

    By default an ordered window frame includes every row with the same ORDER BY value as the current one. Two products with identical sales would then share one running total and the curve would jump. Adding product_id to the ordering makes every row unique, so the ranks and the running totals line up one product at a time.

    Reading the curve

    The chart plots the cumulative share against the rank. A steep start means concentration. Here the curve is steep for the best sellers, then bends: the top 24 products make just over half of sales, and the 80% line is crossed at product 56. The last 64 products together make the final 20%, which is still over a million dollars across three years.

    Common mistakes

    • Ranking by units instead of dollars. Cheap decor sells many units; the question is about sales.
    • Using the curve to cut products by itself. Margin, returns and what sells with what matter more than rank.
    • No tie-breaker in the window. Running totals repeat on ties.

    Interview note

    “How would you find the products that make 80% of revenue?” Describe exactly this: aggregate per product, running sum ordered by revenue with a tie-breaker, divide by the total, filter on the running share. Then add the business caveat about the tail.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.