Appearance
How the tables join
No foreign key is enforced. The schema is a naming contract: the same column name means the same thing, and joins, everywhere.
The keys
| Key | Present in | Joins |
|---|---|---|
seller_partner_id, org_key | every table except cost_dictionary (global) | everything, always |
marketplace_id | all except inventory and cost_dictionary | sales, listings, ads |
stock_region | every table except the six vendor_* tables and cost_dictionary. supply_chain holds the warehouse's territory, the pool's anchor; inventory the physical pool: equal for an unpooled territory, the anchor of the pool otherwise. NULL on an inbound_shipments line whose FC our map does not know yet | anything to inventory: stock is region-grained |
child_asin | all except advertising_search_terms, advertising_placements, advertising_targets, advertising_negative_targets, advertising_impression_share, advertising_budget_usage, advertising_campaign_settings, advertising_target_settings, the two sqp_*, vendor_invoices, vendor_remittances and cost_dictionary | the product spine |
sku | product_metrics, listing_health, inventory, inbound_shipments, orders, orders_live, pnl (NULL on its account rows) and costs (filled on its sku lines, rarely elsewhere). Partial in advertising (exact rows only) and advertising_campaigns (rows of a single SKU only); exact on advertising_hourly (NULL when the stream carries none). Absent from the two sqp_*. On the vendor_* tables, and on a Vendor Central row of listing_health, it is your product code on Amazon's purchase orders, not a merchant SKU | the listing and stock spine |
parent_asin | product_metrics, sqp_monthly, sqp_weekly | search demand to sales: the join that answers "is it the market or is it me". Join on (marketplace_id, parent_asin): a parent ASIN is marketplace-local |
period_start, period_end | the two sqp_* | the week or month axis. SQP is weekly or monthly only: to compare with a daily table, aggregate the daily side to the same period, never a partial one |
keyword | advertising_impression_share, against LOWER(advertising.targeting) where targeting_type = 'keyword' | impression share to spend, on (seller_partner_id, marketplace_id, keyword text). Aggregate the advertising side first: a keyword text spans several targets |
metric_date, snapshot_date | metric_date on product_metrics, account_metrics, pnl, vendor_product_metrics and the six dated advertising* tables (advertising_hourly adds hour); snapshot_date on inventory. On advertising_impression_share it is the day of a rolling 30-day snapshot, not a day of activity | the day axis. Ads days are in the profile's time zone, sales days marketplace-local: a boundary day can differ by one |
campaign_id | the ten ads tables that carry a campaign: every advertising* table except advertising_impression_share (BIGINT; on advertising_budget_usage the campaign rows, with ad_product everywhere: SP, SB and SD ids live in different id spaces) | placements, targets, search terms, negatives, campaigns, the hour, the budget usage, the two settings tables |
ad_group_id, keyword_id | ad_group_id: the ads tables except advertising_placements, advertising_budget_usage and advertising_campaign_settings (campaign grain) and advertising_impression_share. keyword_id: advertising and advertising_search_terms (see target_id below) | search terms, targets, negatives |
target_id | advertising_targets (= advertising.keyword_id on SB and SB video rows) and advertising_target_settings (= advertising.keyword_id on every row) | targets to advertising, with ad_product. The SB rows are the very same rows: never add the two tables. A target's settings to its traffic: with ad_product and target_kind, SB and SB video taken as one product |
dsp_advertiser_id, order_id, line_item_id | dsp only | the DSP spine: an order groups its line items, a line item groups the rows of every cut. dsp joins the rest of the channel on (seller_partner_id, marketplace_id, metric_date) for the P&L reading (product_metrics.dsp_spend, the part of the SELLER line-item spend allocated to products, never added), and on child_asin for the product cut |
portfolio_id | advertising, advertising_search_terms, advertising_placements, advertising_negative_targets, advertising_campaigns, advertising_campaign_settings (today's portfolio, SP) and advertising_budget_usage (its portfolio rows: the portfolio IS the entity) | groups spend across the ads tables. The name is not a join: it is advertising.portfolio_name |
shipment_id to order_id | inbound_shipments.shipment_id = costs.order_id where costs.order_kind = 'inbound' | a shipment to the inbound fees Amazon billed on it (placement, transportation). Aggregate inbound_shipments per shipment first: its rows are per SKU |
shipment_id, sku, fnsku | inbound_shipments (sku shared with inventory, listing_health and product_metrics; fnsku with inventory) | a shipment line to the stock it feeds: inventory on (seller_partner_id, stock_region, sku) |
The three joins behind almost every analysis
Each has one rule that keeps it honest. The percentages were measured on production, on settled days.
Ads to sales: the TACOS join (advertising to product_metrics)
On rows where child_asin is set, the join matches 100% of the time: ad spend guarantees a product_metrics row that day. Two rules:
- Use a LEFT join, or report a "not attributed" line.
asin_linkage = 'shared'rows havechild_asin = NULLand carry about 11 % of Sponsored Products spend (fleet-wide, last 90 days). An INNER join drops them silently. - Aggregate
product_metricsto the ASIN first. It is SKU-grained: the ~7% of ad ASINs with several SKUs carry ~22% of spend, so a join before the aggregation doubles their sales.
sql
WITH sales AS (
SELECT seller_partner_id, marketplace_id, child_asin, metric_date,
SUM(product_sales) AS product_sales
FROM nova_share.product_metrics
GROUP BY 1,2,3,4 -- ASIN grain FIRST, then join
)
SELECT a.child_asin, SUM(a.spend) AS spend, ANY_VALUE(s.product_sales) AS sales
FROM nova_share.advertising a
LEFT JOIN sales s USING (seller_partner_id, marketplace_id, child_asin, metric_date)
WHERE a.ad_product = 'sponsored_products' AND a.metric_date >= CURDATE() - INTERVAL 30 DAY
GROUP BY a.child_asin;Search terms to targets
The key matches 100% of the time, but a keyword spans ~2.3 advertising rows on average (one per attributed ASIN, up to 11). Join a GROUP BY keyword_id projection of advertising, or pull only dimension columns. Otherwise you multiply the search-term spend by that factor.
Ads to stock: the out-of-stock keywords join (advertising to inventory)
Direct, via stock_region: both tables carry it, so there is no marketplace-to-region mapping to maintain.
sql
SELECT a.targeting, a.campaign_name, SUM(a.spend) AS spend_7d
FROM nova_share.advertising a
JOIN nova_share.inventory inv
ON inv.seller_partner_id = a.seller_partner_id
AND inv.stock_region = a.stock_region
AND inv.child_asin = a.child_asin
AND inv.snapshot_date = (SELECT MAX(snapshot_date) FROM nova_share.inventory WHERE fba_available IS NOT NULL)
WHERE a.metric_date >= CURDATE() - INTERVAL 7 DAY
AND inv.fba_sellable = 0 AND inv.fba_incoming = 0
GROUP BY 1, 2 ORDER BY spend_7d DESC; -- money spent advertising empty shelvesTwo more joins
- Ads to placements: the same money, in a different cut. They join on (
seller_partner_id,marketplace_id,metric_date,campaign_id). The spend on each side is the same money: a join to compare the two, never to add them. See Placements. - Search terms to negatives: the negative-candidates join. A
LEFT JOINon (seller_partner_id,marketplace_id,ad_product,ad_group_id) plusLOWER(keyword_text) = LOWER(search_term), withCOALESCE(negative_id, 0) = 0as the "not blocked yet" filter. A Sponsored Brands negative readssponsored_brands: mapsponsored_brands_videoto it on the search-term side. Repeat the join oncampaign_idwithnegative_level = 'campaign': a campaign-level negative hasad_group_id = NULL, and the ad-group join misses it silently.
Not join keys
advertising.skuis filled only onexactrows (about half of spend): a convenience, not a key. Join onchild_asin.- A
currencycolumn: never a join. negative_idalone: the key is (ad_product,negative_level,negative_kind,negative_id), because each ad product and each of Amazon's negative families uses its own id space.