Skip to main content

Dynamic Pivotingpivoting in PostgreSQL

I have a scenario where iI have to pivot a list of rows to columns dynamically  .For a particular order_numberorder_number there might be several products,products. I want all those products to be in a separate column, along with its products id thatproduct_id (that too in columns), but we cannot predict how many products will there for a particular order_numberorder_number.

Attaching a sample input table and desired output.I'm using postgreSQL and I have tried crosstabthe crosstab function but the resultsresult is not correct.

Table values: enter image description hereenter image description here

Desired Ouput:

enter image description hereenter image description here

Dynamic Pivoting in PostgreSQL

I have a scenario where i have to pivot a list of rows to columns dynamically.For a particular order_number there might be several products, I want all those products to be in a separate column along with its products id that too in columns, but we cannot predict how many products will there for a particular order_number.

Attaching a sample input table and desired output.I'm using postgreSQL and have tried crosstab function but the results is not correct.

Table values: enter image description here

Desired Ouput:

enter image description here

Dynamic pivoting in PostgreSQL

I have a scenario where I have to pivot a list of rows to columns dynamically  .For a particular order_number there might be several products. I want all those products to be in a separate column, along with its product_id (that too in columns), but we cannot predict how many products will there for a particular order_number.

Attaching a sample input table and desired output. I have tried the crosstab function but the result is not correct.

Table values: enter image description here

Desired Ouput:

enter image description here

added 299 characters in body; edited title
Source Link
Sandeep
  • 113
  • 1
  • 5

Dynamic Pivoting in PostgreSQL

I have a scenario where i have to pivot a list of rows to columns dynamically. AttachingFor a particular order_number there might be several products, I want all those products to be in a separate column along with its products id that too in columns, but we cannot predict how many products will there for a particular order_number.

Attaching a sample input table and desired output.I'm using postgreSQLpostgreSQL and have tried crosstab function but the results is not correct.

Table values: enter image description here

Desired Ouput:

Desired outputenter image description here

Pivoting in PostgreSQL

I have a scenario where i have to pivot a list of rows to columns dynamically. Attaching a sample input table and desired output.I'm using postgreSQL and have tried crosstab function but the results is not correct.

enter image description here

Desired output

Dynamic Pivoting in PostgreSQL

I have a scenario where i have to pivot a list of rows to columns dynamically.For a particular order_number there might be several products, I want all those products to be in a separate column along with its products id that too in columns, but we cannot predict how many products will there for a particular order_number.

Attaching a sample input table and desired output.I'm using postgreSQL and have tried crosstab function but the results is not correct.

Table values: enter image description here

Desired Ouput:

enter image description here

Source Link
Sandeep
  • 113
  • 1
  • 5

Pivoting in PostgreSQL

I have a scenario where i have to pivot a list of rows to columns dynamically. Attaching a sample input table and desired output.I'm using postgreSQL and have tried crosstab function but the results is not correct.

enter image description here

Desired output