I have a database table which have field counter that counts number of requests to API (by updating it +1), but I want to get these counts for specific date, (for this month). Is it possible to get it? I am using PostgreSQL.
SQL query
CREATE TABLE IF NOT EXISTS Admin (
id SERIAL PRIMARY KEY,
counter INTEGER NOT NULL DEFAULT 0
created_date TIMESTAMP NOT NULL DEFAULT Now()
);
Thanks in advance.
2
Answers
you can use subquery in two cases:
1- If with each request a field is saved in the database, then you will need the number of all fields per month:
Query :
2- If you update the counter after each request, so that the counter in one day equals the number of all requests on the same day.
Query :
I would also recommend using
date_part
function: