From: | Louis-David Mitterrand <vindex+lists-pgsql-sql(at)apartia(dot)org> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | adding "order by" to a "group by" query |
Date: | 2008-12-06 17:10:37 |
Message-ID: | 20081206171037.GA11617@apartia.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi,
This query:
select p.id_person, person_name(p), array_accum(distinct pt.type_fr)
from person p
left join person_to_event x using (id_person)
left join person_type pt using (id_person_type)
where person_name(p) ilike '%will%'
group by p.id_person,person_name(p);
returns:
id_person | person_name | array_accum
-----------+----------------------+-------------------------------
181 | William Eggleston | {comédien}
200 | William H.Macy | {comédien}
242 | William Nicholson | {auteur}
309 | William Friedkin | {réalisateur}
439 | William Shakespeare | {auteur}
591 | William Christie | {musicien}
786 | Paul Andrew Williams | {réalisateur}
1015 | William Mesguich | {comédien,"metteur en scène"}
But if I append this
order by pt.type_fr = 'comédien';
I get this error:
ERROR: column "pt.type_fr" must appear in the GROUP BY clause or be used in an aggregate function
It seems I am using pt.type_fr in an aggregate function (array_accum()),
yet I get the error.
Is there a way to to have a certain pt.type_fr bubble up (or down) in my
search?
Thanks,
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Kretschmer | 2008-12-06 17:26:06 | Re: adding "order by" to a "group by" query |
Previous Message | Oliveiros Cristina | 2008-12-05 22:38:25 | Re: Best way to "and" from a one-to-many joined table? |