1
Hello,
I have a table with a lot of data, and I would like to count the amount of records in each date of this month. So far OK, a COUNT(*)
and a GROUP BY
already resolves.
SELECT
Trunc(td.data_emissao) AS data_emissao
,Count(*) AS quantidade
FROM
tabela_de_dados td
WHERE
Trunc(td.data_emissao,'mm') = Trunc(Sysdate,'mm')
GROUP BY
Trunc(td.data_emissao)
ORDER BY
1 ASC
;
But I also need to know cumulative amount, example; the quantity of day 2 is the sum of the records from day 1 to day 2, and so on, until on the last day I have the total records of the month.
At the end, I would like to return to the table below, as an example
Data_emissao | Quantidade | Quantidade Acumulada
--------------------------------------------------
01/04 | 10 | 10
02/04 | 25 | 35
03/04 | 15 | 50
04/04 | 30 | 80
... | ... | ...
And so on from the whole month. I hope to have clarified the doubt.
Wouldn’t be the same
count(*)
but without grouping by date, only leaving in the conditionwhere
the month and the year you want the total? I don’t know if I understand your doubt well.– Caique Romero
It would work, if I searched day by day the total until that moment. But what I need is the two information in the same table. Example Date 01/04 Records 10 Accumulated Records 10; Date 02/04 Records 25 Accumulated Records 35 - and so on
– Ranier Cordeiro
Search for "Oracle OVER Analytic Function()"
– Motta
Thanks @Motta! Got it!
– Ranier Cordeiro
Analytic Function allow very useful reports !!
– Motta