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

# Examples

> Complete QueryfulQL queries for common questions about your store.

Complete queries to paste into the [query editor](https://docs.queryful.app/user-guide/reports/query-editor.md) and adjust. Each answers a real question. See [Datasets](https://docs.queryful.app/queryfulql/datasets/overview.md) for every metric, dimension and filter.

## Best-selling products last month

Your top products by net sales, with the items sold behind them.

```sql theme={null}
FROM sales
  SHOW net_sales, net_items_sold
  GROUP BY product_title
  DURING last_month
  ORDER BY net_sales DESC
  LIMIT 20
```

## Sales by channel, month on month

Each sales channel's net sales last month, with the change against the month before.

```sql theme={null}
FROM sales
  SHOW net_sales, orders
  GROUP BY sales_channel
  DURING last_month
  COMPARE TO previous_period
  ORDER BY net_sales DESC
  WITH PERCENT_CHANGE
```

## This year against last, by week

Net sales week by week this year, drawn against the same weeks last year.

```sql theme={null}
FROM sales
  SHOW net_sales
  TIMESERIES week
  DURING this_year
  COMPARE TO previous_year_match_day_of_week
  VISUALIZE net_sales TYPE line
```

## Gross profit by vendor

What each vendor earned you after cost of goods, for products with a cost recorded.

```sql theme={null}
FROM sales
  SHOW net_sales, cost_of_goods_sold, gross_profit, gross_margin
  GROUP BY product_vendor
  DURING last_quarter
  ORDER BY gross_profit DESC
```

## New and returning customers

How much of each month's sales came from first-time customers.

```sql theme={null}
FROM sales
  SHOW net_sales, orders
  GROUP BY new_or_returning_customer
  TIMESERIES month
  DURING this_year
  VISUALIZE net_sales TYPE stacked_bar
```

## Sales by the customer's country

Where your buyers are, using the country on the customer behind each order.

```sql theme={null}
FROM sales
  SHOW net_sales, orders
  GROUP BY order.customer.country
  DURING this_year
  ORDER BY net_sales DESC
```

## Top three products for each vendor

The best sellers within each vendor, with everything else in an "Other" row.

```sql theme={null}
FROM sales
  SHOW net_sales
  GROUP BY product_vendor, TOP 3 product_title
  DURING this_year
  WITH GROUP_TOTALS
```

## Discount codes and what they brought in

Each discount code's orders and sales, from the sales and discounts datasets together.

```sql theme={null}
FROM sales, discounts
  SHOW applied_discounts, discounted_orders, net_sales
  GROUP BY discount_name
  DURING last_month
  ORDER BY net_sales DESC
```

## Most-returned products and why

The products returned most this year, by return reason.

```sql theme={null}
FROM returns
  SHOW returned_quantity, returned_value
  GROUP BY product_title, return_line_item_reason
  DURING this_year
  ORDER BY returned_quantity DESC
  LIMIT 25
```

## Stock about to run out

Products by how many days their stock will last at last month's rate of sale, soonest to sell out first.

```sql theme={null}
FROM inventory
  SHOW ending_inventory_units, inventory_units_sold_per_day, days_of_inventory_remaining
  GROUP BY product_title, product_variant_title
  DURING last_month
  ORDER BY days_of_inventory_remaining ASC
  LIMIT 50
```

## Best customers by lifetime spend

Customers with more than one order, by what they've spent with you.

```sql theme={null}
FROM customers
  SHOW total_amount_spent, total_number_of_orders
  WHERE customer_number_of_orders > 1
  GROUP BY customer_id, customer_country
  ORDER BY total_amount_spent DESC
  LIMIT 50
```

## Conversion rate by device

How many online store sessions turned into orders, on mobile, desktop and tablet.

```sql theme={null}
FROM sessions
  SHOW sessions, conversion_rate, added_to_cart_rate
  WHERE human_or_bot_session = 'human'
  GROUP BY session_device_type
  DURING last_month
```

## Payouts this quarter

Each Shopify Payments payout, with the fees taken from it.

```sql theme={null}
FROM payouts
  SHOW payout_amount, payout_fees
  TIMESERIES week
  DURING this_quarter
  WITH TOTALS
```

## Abandoned checkouts recovered

How many abandoned checkouts came back and bought, week by week.

```sql theme={null}
FROM abandoned_checkouts
  SHOW abandoned_checkouts, recovered_checkouts, checkout_recovery_rate
  TIMESERIES week
  DURING last_quarter
```

## Fulfilment speed by location

The median time from order to shipping at each location.

```sql theme={null}
FROM fulfillments
  SHOW orders_fulfilled, median_hours_order_to_shipping, on_time_delivery_rate
  GROUP BY inventory_location_name
  DURING last_month
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.