gpt4 book ai didi

sql - 在 Microsoft SSMS 中运行总计

转载 作者:行者123 更新时间:2023-12-04 08:39:18 25 4
gpt4 key购买 nike

如何在 SSMS 中获得运行总数?

select E.Employee,E.Month,E.Year,E.Salary,
SUM(E.Salary) over (partition by E.Year order by E.Employee) as Cum_Sal
from Employees E
group by E.Employee,E.Month,E.Year,E.Salary
order by E.Year
需要的输出:
enter image description here

最佳答案

尝试这个:

select E.Employee
,E.Month
,E.Year
,E.Salary
,SUM(E.Salary) OVER
(
partition by E.Year
order by CASE E.Month
WHEN 'Jan' THEN 1
WHEN 'Feb' THEN 2
WHEN 'Mar' THEN 3
WHEN 'Apr' THEN 4
WHEN 'May' THEN 5
WHEN 'Jun' THEN 6
WHEN 'Jul' THEN 7
WHEN 'Aug' THEN 8
WHEN 'Sep' THEN 9
WHEN 'Oct' THEN 10
WHEN 'Nov' THEN 11
WHEN 'Dec' THEN 12
END
) as Cum_Sal
from Employees E
order by E.Year

关于sql - 在 Microsoft SSMS 中运行总计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64640062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com