I have this 2 queries that I would like that could be retrieve in onw shot. If I run both separately, they dont work.
SELECT
(SELECT count(id) FROM numeracao WHERE DATA >= '2022-01-01' AND DATA<='2022-12-31' GROUP BY MONTH(DATA)) AS A,
(SELECT SUM(revisoes) FROM numeracao WHERE DATA >= '2022-01-01' AND DATA<='2022-12-31' GROUP BY MONTH(DATA)) AS B ```
Hown can I retrieve both in one shot?
Thanks
CodePudding user response:
You should use a single aggregation query:
SELECT MONTH(DATA) AS month, COUNT(id) AS cnt, SUM(revisoes) AS sum
FROM numeracao
WHERE DATA BETWEEN '2022-01-01' AND '2022-12-31'
GROUP BY MONTH(DATA);
CodePudding user response:
You can use this query for get your results
SELECT SUM(revisoes) AS total_revisoes, COUNT(id) AS count_id FROM numeracao
WHERE DATA >= '2022-01-01' AND DATA <='2022-12-31'
GROUP BY MONTH(DATA)