如何在SQLite查询中计算正在运行的SUM?

编程入门 行业动态 更新时间:2024-10-09 19:18:18
本文介绍了如何在SQLite查询中计算正在运行的SUM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何获取一列,该列是另一列之前的所有值的总和?

How do I get a column that is the sum of all the values before of another column?

推荐答案

通过将表本身与表连接起来(执行所谓的笛卡尔或交叉联接)。参见下面的示例。

You can do it by joining the table with itself (performing a so-called Cartesian or cross join). See the following example.

SELECT a.name, a.gdppc, SUM(b.gdppc) FROM gdppc AS a, gdppc AS b WHERE b.gdppc <= a.gdppc GROUP BY b.id ORDER BY a.gdppc;

给出一个包含国家及其人均GDP的表格,它将为您提供GDP总量的总和

Given a table containing countries and their per capita GDP it will give you a running total of the GDP figure.

Democratic Republic of Congo|329.645|329.645 Zimbabwe|370.465|700.11 Liberia|385.417|1085.527 Burundi|399.657|1485.184 Eritrea|678.954|2164.138 Niger|711.877|2876.015 Central African Republic|743.945|3619.96 Sierra Leone|781.594|4401.554 Togo|833.803|5235.357 Malawi|867.063|6102.42 Mozambique|932.511|7034.931 ...

请注意,这可能会占用大量资源,因为如果表中包含N个元素,它将创建一个包含N * N个元素的临时表。我不会在大桌子上执行它。

Note that this can be a very resource-intensive operation, because if a table has N elements it will create a temporary table with N*N elements. I would not perform it on a large table.

更多推荐

如何在SQLite查询中计算正在运行的SUM?

本文发布于:2023-11-28 08:00:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641576.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正在运行   如何在   SQLite   SUM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!