Subject | Re: [firebird-support] Re: SQL query help |
---|---|
Author | Dimitry Sibiryakov |
Post date | 2006-09-18T12:03:34Z |
On 18 Sep 2006 at 12:23, Svein Erling Tysvaer wrote:
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.
>There may well exist simpler solutions as to how do this in one singleIn FB2 he could use derived tables. In earlier versions - views.
>query, but I'm pretty certain that 'simpler' does not mean simple. A
>stored procedure or two separate queries are the simplest solutions.
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.