统计salary的累计和running_total

统计salary的累计和running_total

https://www.nowcoder.com/practice/58824cd644ea47d7b2b670c506a159a6

-- 法1:聚合窗口函数
select emp_no, salary,
sum(salary)over(order by emp_no) as running_total
from salaries
where to_date = '9999-01-01'
-- 法2:自连接+group by
select a.emp_no, a.salary, sum(b.salary)
from salaries as a, salaries as b
where a.emp_no >= b.emp_no
and a.to_date = '9999-01-01'
and b.to_date = '9999-01-01'
group by a.emp_no
order by a.emp_no

全部评论

相关推荐

昨天 11:01
门头沟学院 golang
HR岗的
投递菜鸟集团等公司10个岗位
点赞 评论 收藏
分享
07-28 00:10
已编辑
门头沟学院 算法工程师
码农索隆:这哥们库库在我帖子下评论
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务