Subject Re: [firebird-support] Re: SQL query help
Author Dimitry Sibiryakov
On 18 Sep 2006 at 12:23, Svein Erling Tysvaer wrote:

>There may well exist simpler solutions as to how do this in one single
>query, but I'm pretty certain that 'simpler' does not mean simple. A
>stored procedure or two separate queries are the simplest solutions.

In FB2 he could use derived tables. In earlier versions - views.
Something like this:

SELECT a.y, a.m, a.c, b.c from
(SELECT EXTRACT(YEAR FROM CreateDate) as y,
EXTRACT(YEAR FROM CreateDate) as m,
COUNT(*) as c FROM MyTable
GROUP BY 1,2) as a
JOIN
(SELECT EXTRACT(YEAR FROM CeaseDate) as y,
EXTRACT(YEAR FROM CeaseDate) as m,
COUNT(*) as c FROM MyTable
GROUP BY 1,2) as b
ON a.y = b.y AND a.m = b.m

--
SY, Dimitry Sibiryakov.