注册 登录
编程论坛 SQL Server论坛

怎么加一行求和

guishensxy 发布于 2011-09-23 09:35, 913 次点击
select c_id,sum(c_amount)
from tb_o_sg
where c_datetime>='2011-7-27' and c_datetime<='2011-8-2' and c_amount>0
group by c_id having sum(c_amount)>0 and sum(c_amount)<25
order by sum(c_amount) asc

6009413    5.00
6009037    5.00
6009206    5.00
6009211    8.00
6009372    10.00
6009183    11.00
8006885    16.00
6009344    16.00
2009938    16.00
8007342    18.00
8007474    18.00
6009314    19.00
8006745    20.00
8007060    20.00
8006880    20.00
8007307    20.00
8006889    20.00
2009976    20.00
8007498    20.00
8007226    20.00


请问怎么在查询后的数据再加一行求和呢?

3 回复
#2
刘杰明2011-09-29 20:48
晕了,杀了我吧
#3
scilent2011-09-30 20:55
一般来说如果需要求和的话,会在程序中写入命令来计算,哪有在数据表中或查询结果中添加一条记录来实现的
#4
muyiyuwen2011-10-01 00:28
select c_id,c_amount
from(
select c_id,sum(c_amount)  c_amount
from tb_o_sg
where c_datetime>='2011-7-27' and c_datetime<='2011-8-2' and c_amount>0
group by c_id having sum(c_amount)>0 and sum(c_amount)<25
union all
select  null  c_id,sum(c_amount)  c_amount
from (select c_id,sum(c_amount)  c_amount
from tb_o_sg
where c_datetime>='2011-7-27' and c_datetime<='2011-8-2' and c_amount>0
group by c_id having sum(c_amount)>0 and sum(c_amount)<25
)
) order by c_amount
 
1