Answer the question
In order to leave comments, you need to log in
How to select users whose first comment falls within a given range?
There is a table of users, and a table of comments.
CREATE TABLE users (
id SERIAL NOT NULL PRIMARY KEY
);
CREATE TABLE comments (
id SERIAL NOT NULL PRIMARY KEY,
user_id INT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT fk_users_comment FOREIGN KEY (user_id) REFERENCES users (id)
ON UPDATE CASCADE
ON DELETE CASCADE
)
Answer the question
In order to leave comments, you need to log in
get user-first comment pairs
select
user_id, first_comment = min(created_at)
group by user_id
where first_comment between _min_date_ and _max_date_
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question