SELECT
  DATE(snapshot_at, 'UTC') AS snapshot_date,
  warehouse_id,
  sku,
  SUM(on_hand) AS on_hand,
  SUM(reserved) AS reserved,
  SUM(on_hand) - SUM(reserved) AS available
FROM `prod.inventory.daily_snapshots`
GROUP BY 1, 2, 3;

-- Keep negative available inventory visible for review.
SELECT
  warehouse_id,
  sku,
  available
FROM daily_available_stock
WHERE available < 0
ORDER BY available;

