Subject | Re: Query Help? |
---|---|
Author | mcbootchek |
Post date | 2004-09-24T06:10:59Z |
--- In firebird-support@yahoogroups.com, Andy Goodchild
<goodieauk@y...> wrote:
what about to use CASE command (FB 1.5). It is realy fast.
Select
yr AS 'Year'
sum(case qtr when 1 then sales ELSE NULL END) AS Q1
sum(case qtr when 2 then sales ELSE NULL END) AS Q2
sum(case qtr when 3 then sales ELSE NULL END) AS Q3
sum(case qtr when 4 then sales ELSE NULL END) AS Q4
SUM(sales) AS TOTAL
FROM ...
WHERE ...
GROUP BY yr
You can use EXTRACT() command to get info about the time (year,
month, day, hour .... weekday, yearday) from DATE, TIME, TIMESTAMP
fields
<goodieauk@y...> wrote:
> Lee Jenkins wrote:Hi,
>
what about to use CASE command (FB 1.5). It is realy fast.
Select
yr AS 'Year'
sum(case qtr when 1 then sales ELSE NULL END) AS Q1
sum(case qtr when 2 then sales ELSE NULL END) AS Q2
sum(case qtr when 3 then sales ELSE NULL END) AS Q3
sum(case qtr when 4 then sales ELSE NULL END) AS Q4
SUM(sales) AS TOTAL
FROM ...
WHERE ...
GROUP BY yr
You can use EXTRACT() command to get info about the time (year,
month, day, hour .... weekday, yearday) from DATE, TIME, TIMESTAMP
fields
> > Very shrewd way of tackling the problem thoughgenius (
>
> I really can not claim the credit...Jo Celko is a bit of an SQL
> he even gets a mention in Helens book in the further readingsection so
> he must be kinda good)I've
>
> > ...I'm
> > look forward to timing it.
>
> Let us know how it performs in comparison to your firs method as
> often wondered how the two approaches compare..