sql - Pivot multiple rows into columns in Redshift -


i working aws redshift , have case have multiple rows unique id , need use sql combine rows 1 column per unique id. i've searched how , looks possible in postgres, however, suggested methods use functions like: string_agg , array_agg not available in aws redshift. possible using redshift? know ways attack problem without using functions?

here's working with. table below represent query gives me rows need form 1 column per id:

+----+----------+---------+-------+ | id | make     | model   | type  | +----+----------+---------+-------+ | 1  | ford     | mustang | coupe |  | 1  | toyota   | celica  | coupe |  | 2  | delorean | btf     | coupe | | 2  | mini     | cooper  | coupe | | 3  | ford     | mustang | coupe | | 3  |          |         |       | +----+----------+---------+-------+ 

what hoping end with:

+----+----------+---------+-------+----------+---------+-------+ | id | make     | model   | type  | make     | model   | type  | +----+----------+---------+-------+----------+---------+-------+ | 1  | ford     | mustang | coupe | toyota   | celica | coupe  | | 2  | delorean | bttf    | coupe | mini     | cooper | coupe  | | 3  | ford     | mustang | coupe |          |        |        | +----+----------+---------+-------+----------+--------+--------+ 

if sample data indicative of data , have max 2 entries per id join on output have requested:

select id, a.make, a.model, a.type, b.make, b.model, b.type yourtable   left outer join yourtable b   on b.id = a.id    , b.make != a.make   , b.model != a.model   , b.type != a.type 

if have more two, spin simple console app in c#, read in data , write out new table.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -