Subject RE: [firebird-support] Group by month based on a timestamp?
Author Mark Rotteveel
On Thu, 15 Dec 2011 15:28:30 +0100, Svein Erling Tysvær
<svein.erling.tysvaer@...> wrote:
>>> I've got data in a table containing timestamps in a timestamp column.
I
>>> want to group these by month.
>>>
>>> How?
>>>
>>> Anything simpler/better than this:
>>> substring(cast(T."TheTimestamp" as varchar(50)) from 1 for 7)
>>
>>select
>> count(*)
>> , extract(month from mytimestamp)
>>from
>> t
>>group by
>> extract(month from mytimestamp)
>
> Or, if you don't want to group November 2010 with November 2011:
>
> select count(*)
> , extract(year from mytimestamp) || '-' ||
> extract(month from mytimestamp) as MyMonth
> from t
> group by 2, 3

I suppose you mean either:

select count(*)
, extract(year from mytimestamp)
, extract(month from mytimestamp) as MyMonth
from t
group by 2, 3

or

select count(*)
, extract(year from mytimestamp) || '-' ||
extract(month from mytimestamp) as MyMonth
from t
group by 2

:)

Mark