SQL:工资的累计
统计salary的累计和running_total
http://www.nowcoder.com/questionTerminal/58824cd644ea47d7b2b670c506a159a6
答案:
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(s2.salary) FROM salaries AS s2 WHERE s2.emp_no <= s1.emp_no AND s2.to_date = '9999-01-01') AS running_total
数据分析阿宇君的SQL题解 文章被收录于专栏
数据分析的SQL题目