Skip to Main Content

Oracle Database Discussions

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!

select's MODEL clause to add columns on the resultset, not just new rows?

Ruslan D.Jul 26 2016 — edited Jul 27 2016

PIVOT can only pivot one value into its one column.

Also PIVOT is not helpful if for examle we want to pivot and (group by) intersecting ranges of values.

So we're planning to use MODEL clause to overcome this limits.

We have to pivot into columns:

- sum(), count() of data over separate quarters for last 2 years and present each quarter's result into its own set of column;

- sum(), count() of data over separate years for last 2 years and present each years's result into its own set of column;

- sum(), count() of data over separate months for last 3  months and present each month's result into its own set of column.

The list of quarters / years / months in the bucketing is fixed and can be hard-coded in the MODEL clause (i.e. it'll be always to look back 2 years).

I have a working prototype doing above using three separate pivots, but it is very inefficient because each pivot has to pass

our huge dataset again.

We expect MODEL might require just one pass over the dataset.

Questions:

- Is it possible for MODEL clause to create new columns (ie. we group by month and product category in a subquery, but MODEL should add columns for the above quarter/year/month buckets)?

- Can't think of a best way to define DIMENSION BY and MEASURES so we could create new columns..

Any ideas are highly appreciated.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 24 2016
Added on Jul 26 2016
10 comments
335 views