I want to present information from a MySQL DB (MariaDB, actually) approximately as follows:
SELECT Client, Year, SUM(Sales)
FROM MySalesTable
GROUP BY Client, Year
ORDER BY Client, Year DESC
The issue is, if there is no data for a particular year for the client, MySQL entirely skips the rows, while I'd like the table to include all years in a range (say: 2015-2022) for all the clients - filled with zeros, nulls, or empty strings.
Normally, I would left-JOIN the query to a table containing bare year numbers (or filter years from a table which includes calendar information of any sort) but I do not have it at hand. I know that I can create a TEMPORARY table and populate it accordingly - but is it possible to create a transient 'pseudotable' on the fly as a subquery? Something like in the pseudocode:
SELECT ... FROM (SELECT Year FROM [2015, 2016,...2022]) LEFT JOIN ....
Thank you very much upfront.