0

I have a table named "Conditions" and I want to pivot the rows and show them as a column. MY original table looks something like this:


sales document  material  condition type  condition value 
123             111111    ybas            100             
123             222222    yzzz            50              
124             333333    ybas            150             
124             333333    yvvv            75             

And I want to transform it into something like this:


sales document  material  ybas  yzzz  yvvv 
123             111111    100              
123             222222          50         
124             333333    150         75  

The values for CONDITION_TYPE are dynamic. I searched the web and I could't find anything. Also, I'm not that advanced in SQL language.

Thanks!

xavier
  • 177
  • 3
  • 15
  • Thanks for the suggestion! The values for CONDITION_TYPE are dynamic.. – xavier Jul 04 '19 at 15:05
  • 2
    If the values for CONDITION_TYPE are dynamic (meaning, they are only known at runtime, when the data is inspected - not when you write the query), then this can't be done in standard SQL. It requires dynamic SQL, which is both an advanced topic and a poor business practice. WHY do you need this pivoting? In almost all cases, the only legitimate need is for DISPLAYING results to an end user. If that's your case, and if you are using a front-end (specialized application) for **reporting**, see if that application has (dynamic) pivoting capabilities; many do, many don't. –  Jul 04 '19 at 15:08
  • 1
    There are plenty of answered questions on this site with dynamic SQL solutions for pivoting. I suggest you read [some of these posts (link)](https://stackoverflow.com/search?q=%5Boracle%5D+dynamic%2Bpivot) and see if some existing solution works for you. – APC Jul 04 '19 at 15:30

0 Answers0