34,594
社区成员
发帖
与我相关
我的任务
分享
declare @t table(goods int,payfee int,act_time4 datetime)
insert into @t
select 100,10,'2008-01-22 00:00:01'
union all select 100,10,'2008-01-22 00:00:01'
union all select 101,5,'2008-01-22 01:00:01'
union all select 102,15,'2008-01-22 12:00:01'
union all select 103,0,'2008-01-23 10:00:01'
union all select 103,0,'2008-01-23 10:00:01'
union all select 104,10,'2008-01-23 22:00:01'
union all select 104,10,'2008-01-23 22:00:01'
select * from @t
select convert(varchar(10),act_time4,120) as act_time4,sum(payfee) as '当天payfee的和'
from @t
group by convert(varchar(10),act_time4,120)
(8 行受影响)
goods payfee act_time4
----------- ----------- -----------------------
100 10 2008-01-22 00:00:01.000
100 10 2008-01-22 00:00:01.000
101 5 2008-01-22 01:00:01.000
102 15 2008-01-22 12:00:01.000
103 0 2008-01-23 10:00:01.000
103 0 2008-01-23 10:00:01.000
104 10 2008-01-23 22:00:01.000
104 10 2008-01-23 22:00:01.000
(8 行受影响)
act_time4 当天payfee的和
---------- -----------
2008-01-22 40
2008-01-23 20
(2 行受影响)
declare @t table(goods int,payfee int,act_time4 datetime)
insert into @t
select 100,10,'2008-01-22 00:00:01'
union all select 100,10,'2008-01-22 00:00:01'
union all select 101,5,'2008-01-22 01:00:01'
union all select 102,15,'2008-01-22 12:00:01'
union all select 103,0,'2008-01-23 10:00:01'
union all select 103,0,'2008-01-23 10:00:01'
union all select 104,10,'2008-01-23 22:00:01'
union all select 104,10,'2008-01-23 22:00:01'
select * from @t
select cast(convert(varchar(10),act_time4,120) as datetime) as act_time4,sum(payfee) as '当天payfee的和'
from @t
group by cast(convert(varchar(10),act_time4,120) as datetime)
(8 行受影响)
goods payfee act_time4
----------- ----------- -----------------------
100 10 2008-01-22 00:00:01.000
100 10 2008-01-22 00:00:01.000
101 5 2008-01-22 01:00:01.000
102 15 2008-01-22 12:00:01.000
103 0 2008-01-23 10:00:01.000
103 0 2008-01-23 10:00:01.000
104 10 2008-01-23 22:00:01.000
104 10 2008-01-23 22:00:01.000
(8 行受影响)
act_time4 当天payfee的和
----------------------- -----------
2008-01-22 00:00:00.000 40
2008-01-23 00:00:00.000 20
(2 行受影响)
declare @t table(goods int,payfee int,act_time4 datetime)
insert into @t
select 100,10,'2008-01-22 00:00:01'
union all select 100,10,'2008-01-22 00:00:01'
union all select 101,5,'2008-01-22 01:00:01'
union all select 102,15,'2008-01-22 12:00:01'
union all select 103,0,'2008-01-23 10:00:01'
union all select 103,0,'2008-01-23 10:00:01'
union all select 104,10,'2008-01-23 22:00:01'
union all select 104,10,'2008-01-23 22:00:01'
select * from @t
select convert(varchar(10),act_time4,120) as act_time4,sum(payfee) as '当天payfee的和'
from (select distinct * from @t)t
group by convert(varchar(10),act_time4,120)
--------------------------------------------------
(8 個資料列受到影響)
goods payfee act_time4
----------- ----------- -----------------------
100 10 2008-01-22 00:00:01.000
100 10 2008-01-22 00:00:01.000
101 5 2008-01-22 01:00:01.000
102 15 2008-01-22 12:00:01.000
103 0 2008-01-23 10:00:01.000
103 0 2008-01-23 10:00:01.000
104 10 2008-01-23 22:00:01.000
104 10 2008-01-23 22:00:01.000
(8 個資料列受到影響)
act_time4 当天payfee的和
---------- -----------
2008-01-22 30
2008-01-23 10
(2 個資料列受到影響)
select cast(convert(varchar(10),act_time4,120) as datetime) as act_time4,sum(Payfee)as Payfee
from tab
group by cast(convert(varchar(10),act_time4,120) as datetime)
declare @t table(goods int,payfee int,act_time4 datetime)
insert into @t
select 100,10,'2008-01-22 00:00:01'
union select 100,10,'2008-01-22 00:00:01'
union select 101,5,'2008-01-22 01:00:01'
union select 102,15,'2008-01-22 12:00:01'
union select 103,0,'2008-01-23 10:00:01'
union select 103,0,'2008-01-23 10:00:01'
union select 104,10,'2008-01-23 22:00:01'
union select 104,10,'2008-01-23 22:00:01'
select * from @t
select convert(varchar(10),act_time4,120) as act_time4,sum(payfee) as '当天payfee的和'
from @t
group by convert(varchar(10),act_time4,120)
(5 行受影响)
goods payfee act_time4
----------- ----------- -----------------------
100 10 2008-01-22 00:00:01.000
101 5 2008-01-22 01:00:01.000
102 15 2008-01-22 12:00:01.000
103 0 2008-01-23 10:00:01.000
104 10 2008-01-23 22:00:01.000
(5 行受影响)
act_time4 当天payfee的和
---------- -----------
2008-01-22 30
2008-01-23 10
(2 行受影响)