> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sales dataset

> LayersQL Sales dataset reference for querying order-level purchase metrics including line items, revenue, returns, and customer attribution windows.

* **Label:** Sales
* **Description:** Order-level metrics from the purchases table.
* **Default group key:** `transaction_id`

## Metrics

* **total\_sales (USD)**
  * Sales after discounts and before taxes/returns.
  * Example: SUM(total\_sales)
* **quantity\_purchased (items)**
  * Number of items purchased.
  * Example: SUM(quantity\_purchased)
* **orders (orders)**
  * Unique orders (`transaction_id`).
  * Example: COUNT\_DISTINCT(orders)
* **line\_items (items)**
  * Unique line items purchased.
  * Example: COUNT\_DISTINCT(line\_items)
* **customers (customers)**
  * Unique customers who purchased.
  * Example: COUNT\_DISTINCT(customers)

## Dimensions

* **transaction\_id:** Shopify order ID.
* **line\_item\_id:** Shopify line item ID.
* **product\_id:** Shopify product ID.
* **variant\_id:** Shopify variant ID.
* **customer\_id:** Shopify customer ID.
* **session\_id:** Session identifier derived from the order.
* **geo\_country:** Country from the shipping address.
* **geo\_state:** State or province from the shipping address.
* **geo\_city:** City from the shipping address.
* **shopping\_channel:** Channel of purchase (e.g., online\_store).
* **marketing\_source:** UTM source.
* **marketing\_medium:** UTM medium.
* **marketing\_campaign:** UTM campaign.
* **device:** Device category derived from User-Agent.
* **browser:** Browser family from User-Agent.

## Examples

Total revenue by country (last 30 days)

```sql theme={null}
FROM sales
SHOW SUM(total_sales)
GROUP BY geo_country
SINCE -30d
```

Order count by marketing source (this month)

```sql theme={null}
FROM sales
SHOW COUNT_DISTINCT(orders)
GROUP BY marketing_source
SINCE this_month
```

Customer count by shopping channel (past 90 days)

```sql theme={null}
FROM sales
SHOW COUNT_DISTINCT(customers)
GROUP BY shopping_channel
SINCE past_90_days
```

## Next steps

* [LayersQL syntax](/platform/layersql/syntax)
* [LayersQL functions](/platform/layersql/functions)
* [Datasets overview](/platform/layersql/datasets)
