SQLite:获取列的总数/总和 [英] SQLite: Get Total/Sum of Column
本文介绍了SQLite:获取列的总数/总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 SQLite 并尝试返回 TOTAL
列中 buy_price
列的总和,同时返回所有数据.我不想/不需要对数据进行分组,因为我需要在每个返回的行中都有数据.
I am using SQLite and am trying to return the total of one column buy_price
in the column TOTAL
while at the same time returning all of the data. I do not want/need to group the data as I need to have the data in each returned row.
id date pool_name pool_id buy_price TOTAL
1 09/01/12 azp 5 20
2 09/02/12 mmp 6 10
3 09/03/12 pbp 4 5
4 09/04/12 azp 7 20
5 09/05/12 nyp 8 5 60
当我包含诸如 SUM(buy_price) as TOTAL
之类的内容时,它只返回一行.我需要返回所有行以及所有 buy_price
条目的总数.
When I include something like SUM(buy_price) as TOTAL
it only returns one row. I need all rows returned along with the total of all buy_price
entries.
推荐答案
这听起来像是您要找的:
It sounds like this is what you are looking for:
select id,
dt,
pool_name,
pool_id,
buy_price,
(select sum(buy_price) from yourtable) total
from yourtable
这篇关于SQLite:获取列的总数/总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文