标签:
公司为了查看用人成本,需要对员工的工资进行累加,以便察看员工人数与工资支出之间的对应关系。下面按照进入公司的先后顺序(人员编号:empno)来累加察看。
创建测试用表:
CREATE OR REPLACE VIEW v AS SELECT ‘101‘ AS empno, ‘ALLEN‘ AS ename, ‘1000‘ AS sal FROM DUAL UNION ALL SELECT ‘102‘ AS empno, ‘JAMES‘ AS ename, ‘1100‘ AS sal FROM DUAL UNION ALL SELECT ‘103‘ AS empno, ‘TOM‘ AS ename, ‘1200‘ AS sal FROM DUAL; SELECT * FROM v;
SQL代码如下:
SELECT empno, ename, sal, SUM(sal) OVER(ORDER BY empno) AS cost FROM v;
执行结果如下:
其中,最后的排序子句只是为了方便观察,与分析函数的结果无关。
标签:
原文地址:http://www.cnblogs.com/minisculestep/p/4894772.html