Re: Lista de valores

From: "Jaime Casanova" <systemguards(at)gmail(dot)com>
To: "manuel lamas" <manuel3w(at)hotmail(dot)com>
Cc: pgsql-es-ayuda(at)postgresql(dot)org
Subject: Re: Lista de valores
Date: 2007-08-08 04:07:43
Message-ID: c2d9e70e0708072107o18a286bfv27b077b952deb2a7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

On 8/7/07, manuel lamas <manuel3w(at)hotmail(dot)com> wrote:
> Hola lista,
>
> Digamos que tengo una tabla asi:
>
> CREATE TABLE T1
> (
> productoID int,
> color varchar(20)
> );
>
>
> INSERT INTO T1(productoID,color)VALUES(1,'blanco');
> INSERT INTO T1(productoID,color)VALUES(1,'negro');
> INSERT INTO T1(productoID,color)VALUES(1,'rojo');
>
> INSERT INTO T1(productoID,color)VALUES(2,'blanco');
> INSERT INTO T1(productoID,color)VALUES(2,'negro');
> INSERT INTO T1(productoID,color)VALUES(2,'rojo');
>
> Quiero hacer un SELECT que me de este resultado sin utilizar una función (en
> un simple SELECT), es posible?
>
> 1 blanco,negro,rojo
> 2 blanco,negro,rojo
>
>

no se si el select es muy complejo para tu gusto.

select productoid,
array_to_string(array(select color from t1
where productoid =
foo.productoid), ',')
from t1 as foo group by productoid;

productoid | array_to_string
------------+-------------------
2 | blanco,negro,rojo
1 | blanco,negro,rojo
(2 rows)

--
Atentamente,
Jaime Casanova

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs and the universe trying
to produce bigger and better idiots.
So far, the universe is winning."
Richard Cook

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message manuel lamas 2007-08-08 04:55:36 Re: Lista de valores
Previous Message Jaime Casanova 2007-08-08 00:21:21 Re: roadmap postgresql