Answer the question
In order to leave comments, you need to log in
How to avoid grouping by id?
Hello!
There is a table:
CREATE TABLE public.vk_app_persononline
(
id integer NOT NULL DEFAULT nextval('vk_app_persononline_id_seq'::regclass),
dt_online timestamp with time zone NOT NULL,
person_id integer NOT NULL,
CONSTRAINT vk_app_persononline_pkey PRIMARY KEY (id),
CONSTRAINT vk_app_persononline_person_id_401633fc_fk_vk_app_persongroup_id FOREIGN KEY (person_id)
REFERENCES public.vk_app_persongroup (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED
)
class PersonOnline(models.Model):
dt_online = models.DateTimeField()
person = models.ForeignKey(PersonGroup)
queryset = PersonOnline.objects.annotate(
count_person=Count('person_id')).annotate(hour_online=Extract('dt_online', 'hour')).filter(person__in=members).values('count_person', 'hour_online')
SELECT COUNT("vk_app_persononline"."person_id") AS "count_person", EXTRACT('hour' FROM "vk_app_persononline"."dt_online" AT TIME ZONE UTC) AS "hour_online" FROM "vk_app_persononline" WHERE "vk_app_persononline"."person_id" IN (SELECT U0."person_id" AS Col1 FROM "vk_app_personsgroups" U0 WHERE U0."group_id" = 1) GROUP BY "vk_app_persononline"."id", EXTRACT('hour' FROM "vk_app_persononline"."dt_online" AT TIME ZONE UTC)
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