把数据库表中数据按照电子表格数据方式处理的方案
1.model子句
model 【return updated rows】
partition by (parameter1,parameter2......parameterN) --分区子句
dimension by (parameter1,parameter2......parameterN) --维度列,用来确定分区中的一列
measures ( parameter1,parameter2......parameterN) --度量值,用来计算和储存单元格值
rules automatic order(求解顺序)( --规则
[order by parameter1,parameter2....parameterN] --自定义求解顺序
-- 计算的方法
)
2.例子
select product, country, year, week, inventory, sale, receipts
from sales_fact
where country in ('Australia')
model return updated rows -返回更新的句,无的话返回所有分区的数据
partition by (product, country)
dimension by (year, week) --以year,week定义维度列
measures ( 0 inventory , sale, receipts) --度量值,inventory新的列,用来储存计算的值
rules automatic order(
inventory [year, week ] =
nvl(inventory [cv(year), cv(week)-1 ] ,0)
- sale[cv(year), cv(week) ] +
+ receipts [cv(year), cv(week) ]
)
order by product, country,year, week