Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql中进行查询计算_Mysql_Sql - Fatal编程技术网

如何在mysql中进行查询计算

如何在mysql中进行查询计算,mysql,sql,Mysql,Sql,这是我的桌子 id daily pre_daily created_at 1 2000 34.50 2019-01-01 14:08:45 2 2450 30.4 2019-01-02 14:08:45 3 3500 33.7 2019-01-03 14:08:45 我想生成以下输出 id daily accumulation 1 2000 2000 2 2450 4450 3 3500 7950

这是我的桌子

id daily pre_daily created_at 1 2000 34.50 2019-01-01 14:08:45 2 2450 30.4 2019-01-02 14:08:45 3 3500 33.7 2019-01-03 14:08:45 我想生成以下输出

id daily accumulation 1 2000 2000 2 2450 4450 3 3500 7950 我怎么能这样计算呢?请帮忙 我想用这样的计算方法重述一个月的数据

您可以使用相关子查询


另外,如果您的版本为8-,则无法使用windows分析功能。

@Ada不客气,兄弟:
select t.id, t.daily,
       (select sum(daily) from tab where id <= t.id ) as accumulation
  from tab t
 order by t.id;

id  daily  accumulation
1   2000   2000
2   2450   4450
3   3500   7950