Здравствуйте!
Есть таблица:
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
)
Django модель:
class PersonOnline(models.Model):
dt_online = models.DateTimeField()
person = models.ForeignKey(PersonGroup)
Django запрос:
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)
Как избежать группровки по id, т.е. этой строки - GROUP BY "vk_app_persononline"."id" ?