order_payloads (payload_id, received_at, payload) holds order messages as JSON text. Three client versions are in use, and the field v says which one sent the payload:
v | order id | items | item fields |
|---|
| 1 | order_id | items | sku, qty, price |
| 2 | order_id | items | sku, qty, unit_price — numbers may arrive as strings ("3") |
| 3 | order.id (nested) | order.lines | sku, quantity, unit_price |
An order can be sent more than once (a client re-sends it after editing it); only the latest received version of each order counts — when two arrive at the same moment, the higher payload_id. An order can have no items.
Report sales by SKU across the current version of every order: units (total quantity) and revenue (total quantity × unit price, rounded to 2 decimal places).
Columns: sku, units, revenue. Sort by sku.