Обсуждение: crosstab

Поиск
Список
Период
Сортировка

crosstab

От
John Fabiani
Дата:
Hi,
I don't know if it because I'm as sick as dog or I'm just a plain idiot - most 
likely a little of both.

Here is my table 

week_of date, 
item_number text,
planned_demand integer.

I have 
week_of        item_number      planned
2012-02-12    00005                200
2012-02-19    00005                -30
2012-02-26    00005                -16

I want to see

item_number   2012-02-12    2012-02-19   2012-02-26
00005                   200                 -30                 -16

I actually have added fields but that should get me started.

Thanks for help from an old man with a very bad cold.

Johnf


Re: crosstab

От
Pavel Stehule
Дата:
Hello

maybe this article helps
http://stackoverflow.com/questions/3002499/postgresql-crosstab-query

there are more ways

Regards

Pavel Stehule



2012/3/12 John Fabiani <johnf@jfcomputer.com>:
> Hi,
> I don't know if it because I'm as sick as dog or I'm just a plain idiot - most
> likely a little of both.
>
> Here is my table
>
> week_of date,
> item_number text,
> planned_demand integer.
>
> I have
> week_of        item_number      planned
> 2012-02-12    00005                200
> 2012-02-19    00005                -30
> 2012-02-26    00005                -16
>
> I want to see
>
> item_number   2012-02-12    2012-02-19   2012-02-26
> 00005                   200                 -30                 -16
>
> I actually have added fields but that should get me started.
>
> Thanks for help from an old man with a very bad cold.
>
> Johnf
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql


Re: crosstab

От
John Fabiani
Дата:
select *
from crosstab('select  item_number::text, week_of::date, planned_demand::text 
from holding_table order by 1,2') 
as ct(row_name text, week_of date, planned text)

The above does not work.  What am I doing wrong?
Johnf
On Monday, March 12, 2012 06:01:21 PM Pavel Stehule wrote:
> Hello
> 
> maybe this article helps
> http://stackoverflow.com/questions/3002499/postgresql-crosstab-query
> 
> there are more ways
> 
> Regards
> 
> Pavel Stehule
> 
> 2012/3/12 John Fabiani <johnf@jfcomputer.com>:
> > Hi,
> > I don't know if it because I'm as sick as dog or I'm just a plain idiot
> > - most likely a little of both.
> > 
> > Here is my table
> > 
> > week_of date,
> > item_number text,
> > planned_demand integer.
> > 
> > I have
> > week_of        item_number      planned
> > 2012-02-12    00005                200
> > 2012-02-19    00005                -30
> > 2012-02-26    00005                -16
> > 
> > I want to see
> > 
> > item_number   2012-02-12    2012-02-19   2012-02-26
> > 00005                   200                 -30                 -16
> > 
> > I actually have added fields but that should get me started.
> > 
> > Thanks for help from an old man with a very bad cold.
> > 
> > Johnf
> > 
> > --
> > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-sql


Re: crosstab

От
Pavel Stehule
Дата:
2012/3/12 John Fabiani <johnf@jfcomputer.com>:
> select *
> from crosstab('select  item_number::text, week_of::date, planned_demand::text
> from holding_table order by 1,2')
> as ct(row_name text, week_of date, planned text)
>
> The above does not work.  What am I doing wrong?

what it does?

do you have tablefunc extension?

http://www.postgresql.org/docs/9.1/interactive/tablefunc.html

regards

Pavel Stehule

> Johnf
> On Monday, March 12, 2012 06:01:21 PM Pavel Stehule wrote:
>> Hello
>>
>> maybe this article helps
>> http://stackoverflow.com/questions/3002499/postgresql-crosstab-query
>>
>> there are more ways
>>
>> Regards
>>
>> Pavel Stehule
>>
>> 2012/3/12 John Fabiani <johnf@jfcomputer.com>:
>> > Hi,
>> > I don't know if it because I'm as sick as dog or I'm just a plain idiot
>> > - most likely a little of both.
>> >
>> > Here is my table
>> >
>> > week_of date,
>> > item_number text,
>> > planned_demand integer.
>> >
>> > I have
>> > week_of        item_number      planned
>> > 2012-02-12    00005                200
>> > 2012-02-19    00005                -30
>> > 2012-02-26    00005                -16
>> >
>> > I want to see
>> >
>> > item_number   2012-02-12    2012-02-19   2012-02-26
>> > 00005                   200                 -30                 -16
>> >
>> > I actually have added fields but that should get me started.
>> >
>> > Thanks for help from an old man with a very bad cold.
>> >
>> > Johnf
>> >
>> > --
>> > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
>> > To make changes to your subscription:
>> > http://www.postgresql.org/mailpref/pgsql-sql
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql