3
I have a system of e-commerce in which N products are sold and I am making a comparison between sales of a particular product per period of time, ie the admin will have an area in which he chooses a product and a crease date (ex: 01/04/2018 - 26/04/2018) to plot this in a line chart making it possible to see the sales evolution of this product over time.
Is there any way, in Mysql itself, to make even dates that have no sales, appear as 0? I know I could generate this range with PHP and search 1 to 1 and generate a array
but wanted to know if there is any direct way in Mysql.
Example:
Produto A
Data Inicial: 01/04/2018
Data Final: 05/04/2018
01/04 - 01 vendidos
02/04 - 04 vendidos
03/04 - 00 vendidos
04/04 - 06 vendidos
05/04 - 00 vendidos
The result of this query would be only
01/04 - 01 vendidos
02/04 - 04 vendidos
04/04 - 06 vendidos
I wish the days were dead, too.
Does a total SELECT COUNT(*) AS no longer show that amount 0?
– marcollahc
I found this topical on the SOEN https://stackoverflow.com/questions/1046865/mysql-select-all-dates-in-a-range-even-if-no-records-present
– Pedro Augusto
http://www.media-division.com/using-mysql-generate-daily-sales-reports-filled-gaps
– user60252
Guys, I treated in PHP itself, but the idea of SOEN that Pedro posted may be that it works, the Leo needs process, that tbm would not be interesting, easier to deal with in the application. Marcolla M, because in this case only those that had lines to count would appear.
– Bruno Boassi