Answer the question
In order to leave comments, you need to log in
How to select data for each month for a year?
Good day to all. In general, the task is the following. You need to select data (more precisely, the average maximum and minimum temperatures) for each month for the current year. To draw a graph for me to have months, I start from January to December and each month has 3 columns (avg.temp., max.temp. and min.temp.). Help write SQL query. I am attaching an image below to make it clear what I need. Thanks in advance.
Answer the question
In order to leave comments, you need to log in
There is not a lot of initial data, so something like that. Basic principle only.
SELECT
MAX(temp) AS Maximum
MIN(temp) AS Minimum
AVG(temp) AS Average
DATE_FORMAT(ctime, '%c') AS Month
FROM temperature
WHERE ctime > NOW() - INTERVAL 1 YEAR AND ctime < NOW()
GROUP BY Month
ORDER BY ctime DESC
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question