How can I create in SQL a function to search how many courses does a company each month from January to December in a specific year (2015)?
In the table fechahora form cursos, I have 1 in June, 1 in July, 3 in August, 1 in November and 0 in the other months. Furthermore I have the dates in this format '2015-01-01' and I need the name of the month.
I'm trying with this SQL statement.
SELECT
MONTHNAME(FECHAHORA) AS 'MONTH',
COUNT(Monthname(FECHAHORA)) AS 'TOTAL'
FROM COURSES
WHERE DATEOFCOURSE BETWEEN '2015-01-01' AND '2015-12-31'
GROUP BY MES
ORDER BY FECHAHORA;
From this statement, I have the results from the months that have a course but I need from January to December.
Best Answer
If you are using MariaDB, use something like this:
More discussion: https://mariadb.com/kb/en/library/sequence-storage-engine/