Re: QUERY PARA QUE ME MUESTRE LOS DATOS DE LA CONSULTA DE HORIZONTAL A VERTICAL

From: Marcelo Diaz <marcelorauldiaz(at)gmail(dot)com>
To: "Guillermo E(dot) Villanueva" <guillermovil(at)gmail(dot)com>
Cc: Hellmuth Vargas <hivs77(at)gmail(dot)com>, MARIA ANTONIETA RAMIREZ SOLIS <maramirez(at)ulsaneza(dot)edu(dot)mx>, Lista Postgres ES <pgsql-es-ayuda(at)postgresql(dot)org>
Subject: Re: QUERY PARA QUE ME MUESTRE LOS DATOS DE LA CONSULTA DE HORIZONTAL A VERTICAL
Date: 2017-09-11 11:03:01
Message-ID: CABu+zmL1+GPE37tu9WBoA2Quz0Y56LkBukjp36ZETOrDcL5STQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

https://www.postgresql.org/docs/9.1/static/tablefunc.html

Marcelo Diaz

2017-09-08 9:50 GMT-03:00 Guillermo E. Villanueva <guillermovil(at)gmail(dot)com>:

> sino también podes usar algo así:
> select
> descripcion,
> SUM(CASE claveservicio WHEN expr THEN expr ELSE 0 END) AS "Columna 1",
> SUM(CASE claveservicio WHEN expr THEN expr ELSE 0 END) AS "Columna 2",
> ....
> from
> tablas
> where
> filtros
> group by
> descripcion
>
>
>
> El 7 de septiembre de 2017, 20:58, Hellmuth Vargas <hivs77(at)gmail(dot)com>
> escribió:
>
>> Hola lista
>>
>> Verifique la función crosstab de la extensión tablefunc
>>
>> https://www.postgresql.org/docs/current/static/tablefunc.html
>>
>> El 7 sept. 2017 5:30 PM, "Maria Antonieta Ramirez" <
>> maramirez(at)ulsaneza(dot)edu(dot)mx> escribió:
>>
>>>
>>> Gracias por contestar.
>>>
>>>
>>> Busque el equivalente y es string_agg en postgres.
>>>
>>>
>>> y mi consulta queda asi:
>>>
>>>
>>>
>>>
>>>
>>>
>>> *SELECT descripcion, string_agg( claveservicio, ',')AS "COLUMNA
>>> 1" FROM educaciondistancia.bancos_maestria where descripcion = 'HSBC' group
>>> by descripcion;*
>>>
>>> y me dio el siguiente resultado:
>>>
>>>
>>> *DESCRIPCION COLUMNA 1 *
>>>
>>> *HSBC 5,6,7 *
>>>
>>>
>>>
>>> Como le puedo hacer si quiero que mi resultado quede de la siguiente
>>> manera:
>>>
>>>
>>> *DESCRIPCION COLUMNA 1 COLUMNA2 COLUMNA 3 *
>>>
>>> *HSBC 5 6
>>> 7 *
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> ------------------------------
>>> *De:* Felipe Contreras Oyarzún <fcontreras(dot)oyarzun(at)gmail(dot)com>
>>> *Enviado:* jueves, 7 de septiembre de 2017 16:40:38
>>> *Para:* Maria Antonieta Ramirez
>>> *Asunto:* Re: QUERY PARA QUE ME MUESTRE LOS DATOS DE LA CONSULTA DE
>>> HORIZONTAL A VERTICAL
>>>
>>> busca el equivalente a group_concat de mysql
>>>
>>> El 7 de septiembre de 2017, 18:27, Maria Antonieta Ramirez <
>>> maramirez(at)ulsaneza(dot)edu(dot)mx> escribió:
>>>
>>>>
>>>> Buena tarde,
>>>>
>>>>
>>>> Disculpen hay alguna forma en la que pueda mostrarme postgres el
>>>> resultado de mi consulta de forma vertical?
>>>>
>>>>
>>>> como ejemplo tengo la siguiente consulta:
>>>>
>>>>
>>>> select clave, nombre, apellido_paterno
>>>>
>>>> from alumnos
>>>>
>>>> where id= 1;
>>>>
>>>>
>>>>
>>>> Les agradezco mucho por su tiempo tomado.
>>>>
>>>>
>>>> Gracias.
>>>>
>>>
>>>
>

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Alvaro Herrera 2017-09-11 11:54:55 Re: QUERY PARA QUE ME MUESTRE LOS DATOS DE LA CONSULTA DE HORIZONTAL A VERTICAL
Previous Message Guillermo E. Villanueva 2017-09-08 12:50:20 Re: QUERY PARA QUE ME MUESTRE LOS DATOS DE LA CONSULTA DE HORIZONTAL A VERTICAL