关于sum求和问题

satanail 2010-05-14 09:55:23
有这样的一个表
fee_tatal time
3400 2006-10-11 14:17:14.000
1250 2006-10-11 14:17:14.000
3300 2006-10-11 14:17:14.000
5000 2006-10-12 13:59:20.000
-3000 2006-10-12 13:59:20.000
-1500 2006-10-14 14:42:50.000
2500 2006-10-14 14:42:50.000
. .
. .
. .
. .

我要是想取个时间段内的时间例如 2006-10-11到2006-10-14内的
每天的fee_tatal之合我该如何写??

请大家帮下忙~~
...全文
45 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jaydom 2010-05-14
  • 打赏
  • 举报
回复

use PracticeDB
go
if exists (select 1 from sysobjects where name like '%tb_a%')
drop table tb_a
go
create table tb_a
(
fee_tatal numeric(7),
time datetime
)
go
insert into tb_a
select 3400 ,'2006-10-11 14:17:14.000' union all
select 1250 ,'2006-10-11 14:17:14.000' union all
select 3300 ,'2006-10-11 14:17:14.000' union all
select 5000 ,'2006-10-12 13:59:20.000' union all
select -3000 ,'2006-10-12 13:59:20.000' union all
select -1500 ,'2006-10-14 14:42:50.000' union all
select 2500 ,'2006-10-14 14:42:50.000'
go


select * from tb_a

select SUM(fee_tatal) fee_tatal,time
from tb_a
where ConverT(varchar(10),time,120)>='2006-10-11' and ConverT(varchar(10),time,120)<='2006-10-14'
group by time

htl258_Tony 2010-05-14
  • 打赏
  • 举报
回复
select convert(varchar,time,23) time,sum(fee_tatal ) fee_tatal 
from tb
where time>='2006-10-11' and time<dateadd(dd,1,'2006-10-14')
group by convert(varchar,time,23)
给你补充完整吧
sql_sf 2010-05-14
  • 打赏
  • 举报
回复
if object_id('[tb]') is not null drop table [tb]
go
create table [tb] (fee_tatal int,[time] datetime)
insert into [tb]
select 3400,'2006-10-11 14:17:14.000' union all
select 1250,'2006-10-11 14:17:14.000' union all
select 3300,'2006-10-11 14:17:14.000' union all
select 5000,'2006-10-12 13:59:20.000' union all
select -3000,'2006-10-12 13:59:20.000' union all
select -1500,'2006-10-14 14:42:50.000' union all
select 2500,'2006-10-14 14:42:50.000'
select sum(fee_tatal)[sum]
from tb
where convert(varchar(10),[time],120)
between '2006-10-11' and '2006-10-14'
/*
sum
-----------
10950

(1 個資料列受到影響)
*/
sql_sf 2010-05-14
  • 打赏
  • 举报
回复
select sum(fee_tatal)[sum]
from tb
where convert(varchar(10),[time],10)
between '2006-10-11' and '2006-10-14'
htl258_Tony 2010-05-14
  • 打赏
  • 举报
回复

select convert(varchar,time,23) time,sum(fee_tatal ) fee_tatal 
from tb
where time between ... and ...
group by convert(varchar,time,23)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧