Subject Re: [firebird-support] query per year
Author Helen Borrie
At 05:21 PM 8/12/2004 +0100, you wrote:

>Hi all,
>
>I want to make a query it which I count for each person the number of
>encounters for each year.
>So I want something like:
>SELECT PersId, Extract (YEAR FROM EncDate) as EncYear, Count(Id) FROM
>Encounter
> GROUP BY PersId, EncYear ODER BY PersId, EncYear.
>
>This is not correct. What is wrong?

You can't refer to a derived field (EncYear) by name in a GROUP BY or ORDER
BY clause. Do this:

SELECT
PersId,
Extract (YEAR FROM EncDate) as EncYear,
Count(Id)
FROM Encounter
GROUP BY 1, 2
ORDER BY 1, 2

./hb