27,579
社区成员
发帖
与我相关
我的任务
分享
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
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)
给你补充完整吧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 個資料列受到影響)
*/
select sum(fee_tatal)[sum]
from tb
where convert(varchar(10),[time],10)
between '2006-10-11' and '2006-10-14'
select convert(varchar,time,23) time,sum(fee_tatal ) fee_tatal
from tb
where time between ... and ...
group by convert(varchar,time,23)