I am setting up an e-commerce where I have an area to generate sales reports. These reports are broken down by year and month.
Currently I have a query sql
where I segment the results by year and month and then I get the results I want, for example:
- Sales
- Total sales;
- Total sales in R $;
- Product
- List of products;
- Best selling product;
- Shipping
- Total sales sent by mail;
- Total sales shipped by carrier;
- Payment
- Total online payments;
- Total deposit payments;
And so on ...
My question is the following, as the reports are fixed, that is, when the month ends, you no longer have the data for that month, would it be better for me to save a table with the reports? Or should I keep them through a new query and filter this information every time the user accesses the reporting page?
When doing the query every time I need to display the report, I feel it is a very heavy and time consuming query because there are several related tables, for example, tipoPagamento
, tipoEntrega
, cliente
, etc. .
Already registering the report data in a table, the query is simpler, but I will have more information in the database. Note: Within the save scheme in a new table, only the list of products is that would remain through query, as it would generate unnecessary duplication.
I am using PHP
and database MySql
.