My database table looks like this:
CREATE TABLE record (
id int,
status int,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
And I want to create a generic query to get count of record
created on every single day in given period period of time(30 days , 1 week , 3 days etc).
For EXAMPLE, I want to know in last 30 days on every single day how many records are created.
Expected Output if duration is 3 days:
Number of day : issue count
day1 : 2
day2 : 3
day3 : 3
What I have so far:
With a little help from stackoverflow I am able to create a query to calculate the count for a single day. To get this for whole week or month, I would need to run this query for every single day separately?
select COUNT(id)
from record
where extract(isodow from created_at) = 1
and created_at >= current_date - 7;