select p_id,paid_amount,date, from payments
这是我的查询,它工作正常,但当我添加总和列时,它只选择第一行。
select p_id,paid_amount,date,sum(paid_amount) as 'sum' from payments
答案 0 :(得分:1)
Most DBMSes support Windowed Aggregates, then it's a simple
select p_id,paid_amount,date,
sum(paid_amount) over () as "sum"
from payments
Otherwise you can use a Scalar Subquery:
select p_id,paid_amount,date,
(select sum(paid_amount) from payments) as "sum"
from payments
答案 1 :(得分:0)
进行两次查询。
SELECT p_id,paid_amount,date, FROM payments;
SELECT SUM(paid_amount) FROM payments;