Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PIVOT alternative

LouiKaJun 13 2017 — edited Jun 14 2017

Hi experts! I’m new to PL/SQL and currently facing the following issue:

I’m trying to transform the data from the database, which looks like this:

ID         Date                SalesForecast

111      13.06.17          100

111      14.06.17          110

111      15.06.17          90

222      13.06.17          50       

333      14.06.17          100

333      15.06.17          100

... into something like that:

            (13.06.17)                        (14.06.17)                   (15.06.17)

ID         SalesForecastDay1     SalesForecastDay2     SalesForecastDay3

111      100                                  110                              90

222      50                                    0                                  0

333      0                                      100                              100

I already achieved this result by using a pivot clause. However, the dates are dynamic, which means SalesForecastDay1 should be sysdate / SalesForecastDay2 = sysdate + 1 / SalesForecastDay3= sysdate +2

Since this is kinda hard to realize in a pivot clause, I was wondering whether there is a different approach to solve this problem.

If you guys have any ideas or maybe an idea what to google for, I would be very grateful for any advice!

Many thanks!

This post has been answered by mathguy on Jun 13 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 12 2017
Added on Jun 13 2017
8 comments
3,512 views