oracle数据库的model,68.Oracle数据库SQL开发之 高级查询——使用MODEL子句

68.Oracle数据库SQL开发之 高级查询——使用MODEL子句

10g中新增的MODEL子句可以用来进行行间计算。允许像访问数组中元素那样访问记录中的某个列。

查询获取2003年内每个月由员工21完成的产品类型为#1和#2的销量,并根据2003年的销售数据预测出2004年1月、2月和3月的销量。

store@PDB1> selectprd_type_id,year,month,sales_amount from all_sales where prd_type_id between 1and 2 and emp_id=21

model

partitionby (prd_type_id)

dimensionby (month,year)

measures(amount sales_amount) (sales_amount[1,2004]=sales_amount[1,2003],

sales_amount[2,2004]=sales_amount[2,2003]+sales_amount[3,2003],

sales_amount[3,2004]=round(sales_amount[3,2003]*1.25,2))

order byprd_type_id,year,month;

PRD_TYPE_ID    YEAR        MONTH SALES_AMOUNT

----------- ---------- ----------------------

1    2003              1     10034.84

1    2003              2     15144.65

1    2003              3     20137.83

1    2003              4     25057.45

1    2003              5     17214.56

1    2003              6     15564.64

1    2003              7     12654.84

1    2003              8     17434.82

1    2003              9     19854.57

1    2003            10    21754.19

1    2003            11    13029.73

1    2003            12    10034.84

1    2004              1     10034.84

1    2004              2     35282.48

1    2004              3     25172.29

2    2003              1      1034.84

2    2003              2      1544.65

2    2003              3      2037.83

2    2003              4      2557.45

2    2003              5      1714.56

2    2003              6      1564.64

2    2003              7      1264.84

2    2003              8      1734.82

2    2003              9      1854.57

2    2003            10     2754.19

2    2003            11     1329.73

2    2003            12     1034.84

2    2004              1      1034.84

2    2004              2      3582.48

2    2004              3      2547.29

30 rows selected.

PARTITION BY(prd_type_id) 指定结果是根据prd_type_id分区的。

DIMENSION BY(month,year)定义数组的位数是month和year

MEASURES(amount sales_amount)表名数组中的每个单元包好一个数量,同时表名数组名为sales_amount.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值