gpt4 book ai didi

mysql - 天数累计

转载 作者:可可西里 更新时间:2023-11-01 07:19:25 24 4
gpt4 key购买 nike

我有一个如下所示的 MySQL 表:

date         count
2010-01-01 5
2010-01-02 6
2010-01-03 7

如何将每一天的总和累加到下一天?所以结果是这样的:

date         acum per day
2010-01-01 5
2010-01-02 11
2010-01-03 18

我想我需要某种 for(each date)... 但没有线索。


这只是我在 Eric 的回答之后使用的最后一个查询。 (谢谢)。

从 SELECT t1.dia, sum(t2.operacions), sum(t2.amount)

(SELECT count(*) operations, sum(amount), date(b.timestamp) dia
FROM transactions b group by date(b.timestamp)) t1

INNER JOIN

(SELECT count(*) operations, sum(amount), date(b.timestamp) dia
FROM transactions b group by date(b.timestamp)) t2

ON t2.dia <= t1.dia GROUP BY t1.dia

最佳答案

嗯,我认为这可行,但不确定性能如何:

SELECT t1.date, sum(t2.count)
FROM mytable t1 INNER JOIN mytable t2 ON t2.date <= t1.date
GROUP BY t1.date

关于mysql - 天数累计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3095135/

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