Spanish Total.js
Español
Documentación Para agentes de IA
Contenido

Make a sales report with SQL

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

.md Sitio web

Esta página aún no está traducida. Estás leyendo el original.

En esta página

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:

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:
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.

Hecho en Europa