数据分析阿宇君 level
获赞
2317
粉丝
47
关注
3
看过 TA
56
中国传媒大学
2021
数据分析师
IP属地:未知
暂未填写个人简介
私信
关注
答案: SELECT s1.emp_no, s1.salary, (SELECT SUM(s2.salary) FROM salaries AS s2 WHERE s2.emp_no <= s1.emp_no AND s2.to_date = '9999-01-01') AS running_total FROM salaries AS s1 WHERE s1.to_date = '9999-01-01' ORDER BY s1.emp_no难点在于:running_total为前N个当前( to_date = '9999-01-01')员工的salary累计 (SELECT SUM(s...
牛客112736836号:可以先进行表连接再用group by 获取running_total 代码如下:select s.emp_no, s.salary, t.running_total from salaries as s left join (select s1.emp_no, sum(s2.salary) as running_total from (select emp_no, salary from salaries where to_date='9999-01-01' ) as s1 left join (select emp_no, salary from salaries where to_date='9999-01-01' ) as s2 on s1.emp_no >=s2.emp_no group by s1.emp_no) as t on s.emp_no = t.emp_no where to_date = '9999-01-01'
0 点赞 评论 收藏
分享
关注他的用户也关注了:
牛客网
牛客企业服务