Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am doing an election system, I am doing a graphic with ChartJS, so I need to COUNT votes GROUP BY date, then sum it with previous day

|voters_id|     created_at       |

6         20/07/2022
7         21/07/2022
9         21/07/2022
14        22/07/2022
21        22/07/2022

The output that I want is:

----------------------------------------- > (old + today) 
on date 20/07 i must have votation count= (0 +1) = 1 
on date 21/07 i must have votation count= (1 +2) = 3 
on date 22/07 i must have votation count= (3 +2) = 5 

How should I write this query?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use count() with windowing function. ie:

select distinct created_at, count(*) over (order by created_at) as votes
from mytable;

DBFiddle demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading