Subject | RE: [firebird-support] Group by month based on a timestamp? |
---|---|
Author | Mark Rotteveel |
Post date | 2011-12-15T14:39:02Z |
On Thu, 15 Dec 2011 15:28:30 +0100, Svein Erling Tysvær
<svein.erling.tysvaer@...> wrote:
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
<svein.erling.tysvaer@...> wrote:
>>> I've got data in a table containing timestamps in a timestamp column.I
>>> want to group these by month.I suppose you mean either:
>>>
>>> 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
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