skip to Main Content

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

2

Answers


  1. 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);
    
    Login or Signup to reply.
  2. 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)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search