Hi
I need a series of month numbers like 201212, 201301 MM to join
other sources against it.
I've got a table that describes projects:
projects ( id INT, project TEXT, startdate DATE )
and some others that log events
events( project_id INT, createdate DATE, ...)
to show some statistics I
hi andreas,
this might give you an idea how to generate series of dates (or other
datatypes):
select g, (current_date + (g||' month')::interval)::date from
generate_series(1,12) g;
regards
jan
Am 22.01.2013 um 22:41 schrieb Andreas :
> Hi
> I need a series of month numbers like 201212, 2013
or even
select m from generate_series( '20121101'::date, '20130101'::date, '1
month'::interval) m;
On Tue, Jan 22, 2013 at 3:49 PM, jan zimmek wrote:
> hi andreas,
>
> this might give you an idea how to generate series of dates (or other
> datatypes):
>
> select g, (current_date + (g||' month
Thanks Filip,
with your help I came a step further. :)
Could I do the folowing without using a function?
CREATE OR REPLACE FUNCTION month_series ( date )
RETURNS table ( monthnr integer )
AS
$BODY$
select to_char ( m, 'MM' )::integer
fromgenerate_series ( $1, current_date,
I would create a common table expression with the series from Filip and left
join to the table you need to report on.
Sent from my smartphone
- Reply message -
From: "Andreas"
To: "Filip Rembiałkowski"
Cc: "jan zimmek" ,
Subject: [SQL] need some magic with generate_series()
Date: Tue,
The query should work for all projects in the projects table where
everyone has a seperate startdate for the series.
For the join I need ( project_id, month_nr ).
When I tried I couldn't figure out how to feed the startdate into
Filip's expression without using the function to encapsulate the
Create a CTE with the project code and starting month of the project. Left join
to month series CTE.
Sent from my smartphone
- Reply message -
From: "Andreas"
To: "Alexander Gataric"
Cc: "Filip Rembiałkowski" , "jan zimmek"
,
Subject: [SQL] need some magic with generate_series()
Date