---
title: Make a sales report with SQL
project: Tables
version: 7.0
section: recipes
language: de
translation: missing
license: Total.js Enterprise
url: https://totaljs.es/docs/de/tables/7-0/recipes/sales-report-with-sql/
updated: 2026-11-20T06:39:57.622Z
---

# Make a sales report with SQL

> Sum the orders of each customer with a SQL query on the view of the Orders table.

Because every table is a PostgreSQL table, you can make reports with SQL. This recipe sums the orders of each customer.

## The query

The view `v` + table ID has the name of the linked customer in the relation column. With *Orders* = `t118h7`, `x02` = Customer and `x04` = Amount:

```sql
SELECT x02 AS customer, COUNT(*) AS orders, SUM(x04) AS total
FROM vt118h7
GROUP BY x02
ORDER BY total DESC;
```

## Run it

- In any PostgreSQL client connected to the database of Tables, for example `psql` or a reporting tool.
- Or through the API with a token that has **Super admin privileges**:

```bash
curl -s -X POST https://tables.yourdomain.com/api/ -H 'x-token: YOUR_TOKEN' -H 'content-type: application/json' \
	-d '{ "schema": "Data|sql", "data": { "sql": "SELECT x02 AS customer, SUM(x04) AS total FROM vt118h7 GROUP BY x02" } }'
```

The structure of the tables and views is in [Database structure](../../reference/database/).
