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

# Examples

> End-to-end StockfulQL queries for common questions

A set of complete queries you can paste into the report editor and adjust. Each one names a dataset, shows a metric or two, and adds the clauses needed to answer a real question. See [Datasets](/stockfulql/datasets/overview) for the metrics, dimensions and filters each one exposes.

## Top sellers last month

Your best products by revenue, with the units behind them.

```sql theme={null}
FROM sales
  SHOW total_revenue, units_sold
  GROUP BY product
  DURING last_month
  ORDER BY total_revenue DESC
  LIMIT 20
```

## Revenue by vendor, month over month

Revenue per vendor last month, each with its change against the month before.

```sql theme={null}
FROM sales
  SHOW total_revenue
  GROUP BY vendor
  DURING last_month
  COMPARE TO previous_period
  ORDER BY total_revenue DESC
```

## What needs reordering

The SKUs running low, soonest to run out first.

```sql theme={null}
FROM inventory
  SHOW days_of_supply, current_quantity, units_to_order
  GROUP BY sku
  WHERE needs_reorder
  ORDER BY days_of_supply ASC
```

## Dead stock, ranked by cash tied up

Products with no recent sales, most valuable first, so you clear the biggest wins.

```sql theme={null}
FROM inventory
  SHOW inventory_value
  GROUP BY product
  WHERE dead_stock
  ORDER BY inventory_value DESC
```

## Return rate by reason

Why customers send things back, and how much.

```sql theme={null}
FROM returns
  SHOW units_returned
  GROUP BY reason
  ORDER BY units_returned DESC
  VISUALIZE units_returned TYPE donut
```

## Least reliable suppliers

On-time delivery rate per supplier, worst first, with how late they run on average.

```sql theme={null}
FROM supplier_performance
  SHOW on_time_rate, deliveries, avg_days_late
  GROUP BY supplier
  ORDER BY on_time_rate ASC
```

## Inventory value by vendor

Where your stock value sits, as a donut.

```sql theme={null}
FROM inventory
  SHOW inventory_value
  GROUP BY vendor
  ORDER BY inventory_value DESC
  VISUALIZE inventory_value TYPE donut
```

## Sales trend over the last year

Revenue by month, to see the shape of the year.

```sql theme={null}
FROM sales_history
  SHOW total_revenue
  TIMESERIES month
  SINCE -12m UNTIL today
```

## Units sold next to stock on hand, by vendor

Combine two datasets with `+` to pull metrics from both. Here last month's units sold sit beside the units you hold now, per vendor, so fast sellers running low and stock that is not moving both stand out in one report.

```sql theme={null}
FROM sales + inventory
  SHOW units_sold, total_quantity
  GROUP BY vendor
  DURING last_month
  ORDER BY units_sold DESC
```

A vendor with sales but no stock left has sold out; one with stock but no sales is sitting dead. See [FROM and SHOW](/stockfulql/syntax/from-and-show) for how combining works.
