Rows to columns

Started by Josué Maldonadoabout 22 years ago2 messagesgeneral
Jump to latest
#1Josué Maldonado
josue@lamundial.hn

Hello List,

I have a table that look like this:

create table estad
(nprodfk int, cmes char(6), hmes char(5),
nqty numeric(12,2), nsold numeric(12,5),
ncost numeric(12,2));

It contains this data:

insert into estad
values (25,'200402','FEB04',500,5000,2300);

insert into estad
values (25,'200401','ENE04',700,6200,2900);

insert into estad
values (25,'200312','DIC03',950,7100,3000);

insert into estad
values (25,'200311','NOV03',360,3900,1760);

insert into estad
values (25,'200310','OCT03',490,4600,1850);

The problem is I need show the data in this way:

TIPO OCT03 NOV03 DIC03 ENE04 FEB04
--------------------------------------------------------
NQTY 490 360 950 700 500
NSOLD 4600 3900 7100 6200 5000
NCOST 1850 1760 3000 2900 2300

Any idea or suggestion?

Thanks in advanced.

--

Josu� Maldonado

#2Joe Conway
mail@joeconway.com
In reply to: Josué Maldonado (#1)
Re: Rows to columns

Josu� Maldonado wrote:

The problem is I need show the data in this way:

TIPO OCT03 NOV03 DIC03 ENE04 FEB04
--------------------------------------------------------
NQTY 490 360 950 700 500
NSOLD 4600 3900 7100 6200 5000
NCOST 1850 1760 3000 2900 2300

Any idea or suggestion?

See contrib/tablefunc for a function called crosstab().

HTH,

Joe