model子句
把數據庫表中數據按照電子表格數據方式處理的方案
1.model子句
model 【return updated rows】
partition by (parameter1,parameter2......parameterN) --分區子句
dimension by (parameter1,parameter2......parameterN) --維度列,用來確定分區中的一列
measures ( parameter1,parameter2......parameterN) --度量值,用來計算和儲存單元格值
rules( --規則
-- 計算的方法
)
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
model子句