查询以计算工资的累计和总 SUM [英] Query to calculate both cumulative and total SUM over salary

查看:68
本文介绍了查询以计算工资的累计和总 SUM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Name  Location  Salary
smith newyork   6000 
adam  dallas    5000
rams  delhi     7000
scott laondon   4000 

输出应该是这样的

Name  Location  Salary Running_salary  total_salary
smith newyork   6000    6000            22000
adam  dallas    5000    11000           22000 
rams  delhi     7000    18000           22000
scott lndon     4000    22000           22000

推荐答案

SELECT name,
location,
salary,
SUM(salary) OVER ( ORDER BY name) AS running_Salary,
/* order by name can replaced with rownum or rowid , but has to be some
column for perfect ordering as internal order is not judgeable */
SUM(salary) OVER () AS total_salary
FROM yourtable

SQL 小提琴

这篇关于查询以计算工资的累计和总 SUM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆