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.