gpt4 book ai didi

mysql - Slamdata:如何根据日期查找累计和

转载 作者:行者123 更新时间:2023-11-30 22:16:31 25 4
gpt4 key购买 nike

我用过SlamData的查询功能。我的代码:

SELECT  
DATE_PART("year",thedate) AS year,DATE_PART("month",thedate) AS month,
SUM(runningPnL) AS PnL
FROM "/Mickey/testdb/sampledata3" AS c

GROUP BY DATE_PART("年", thedate) ,DATE_PART("月", thedate)
按 DATE_PART("year", thedate) ,DATE_PART("month", thedate) 排序

我的表格摘录:

PnL                 month      year  
-1651.8752 1 2001
17180.4776 2 2001
48207.54560000001 3 2001

现在,我怎样才能找到 PnL 的累计总和?
例如-1651.8752第一个月
15528.6024 第二个月
非常感谢 >.<

最佳答案

我正在为累积总和生成与您相​​同的样本数据。希望您从中有所了解。

Create table tempData 
(
pnl float,
[month] int,
[year] int
)
Go
insert into tempData values ( -1651.8752, 1,2001)
insert into tempData values ( 17180.4776, 2,2001)
insert into tempData values ( 48207.54560000001, 3,2001)

Select * , (SELECT SUM(Alias.pnl)
FROM tempData As Alias
WHERE Alias.[Month] <= tempData.[Month]
) As CumulativSUM
FROm tempData
ORDER BY tempData.[MOnth]

关于mysql - Slamdata:如何根据日期查找累计和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38094076/

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