Answer the question
In order to leave comments, you need to log in
How to count the number of messages sent to a user?
You need to select users who received more than N notifications in the last 24 hours.
There are two tables:
1. public.user
create table public.user
(
"id" serial primary key,
"email" varchar(30) unique not null
);
create table public.notification
(
"id" serial PRIMARY KEY,
"user_id" serial REFERENCES public.user (id) ON DELETE CASCADE,
"sent_timestamp" timestamp default current_timestamp
);
SELECT public.user.email
FROM public.user
WHERE public.user.email IN ('[email protected]', '[email protected]')
AND
(
SELECT COUNT (*) FROM
(SELECT *
FROM public.user
INNER JOIN public.notification ON public.user.id = public.notification.user_id
WHERE public.notification.sent_timestamp > NOW() - (1440 * interval '1 minute')
) as c
WHERE public.user.email IN ('[email protected]', '[email protected]')
) > 10
;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question