[Lazarus] SQL question

Ondrej tondrej at gmail.com
Mon Feb 8 14:48:51 CET 2010


On 8 February 2010 14:20, Martin <lazarus at mfriebe.de> wrote:
[snip]
> Do you need the subqueries?
>
> select
>   a.type,
>   sum( if(extract(year from date) = 2008, 1, 0) ) c2008,
>   sum( if(extract(year from date) = 2009, 1, 0) ) c2009
> from Table a
> WHERE a.date between '1.1.2008' and '31.12.2009';

No, of course not. Your suggestion should work fine, too. I would
suspect that there might be a slight performance hit, depending on the
size of the table and existing indexes - unless the Firebird optimizer
is much smarter now. ;-) Probably the best is to try them both and
choose the one which performs better.




More information about the Lazarus mailing list