求一个关于时期的sql语句??

shenzhen_20081203 2008-03-22 12:26:19
tableA
No money dates
1 20 2008-01-12 12:56:21
2 18 2008-01-12 15:32:45
3 31 2008-01-12 21:16:14
4 11 2008-01-13 13:12:23
5 54 2008-01-13 15:21:32
6 17 2008-01-13 21:34:55
7 12 2008-01-14 12:56:21
8 15 2008-01-14 13:33:22
9 61 2008-01-15 10:26:36
10 20 2008-01-15 15:26:43

得到的效果为 (按天统计Money)
Money Dates
69 2008-01-12
82 2008-01-13
27 2008-01-14
81 2008-01-15


...全文
23 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Limpire 2008-03-22
--> 测试数据: #A
if object_id('tempdb.dbo.#A') is not null drop table #A
create table #A (No int,money int,dates datetime)
insert into #A
select 1,20,'2008-01-12 12:56:21' union all
select 2,18,'2008-01-12 15:32:45' union all
select 3,31,'2008-01-12 21:16:14' union all
select 4,11,'2008-01-13 13:12:23' union all
select 5,54,'2008-01-13 15:21:32' union all
select 6,17,'2008-01-13 21:34:55' union all
select 7,12,'2008-01-14 12:56:21' union all
select 8,15,'2008-01-14 13:33:22' union all
select 9,61,'2008-01-15 10:26:36' union all
select 10,20,'2008-01-15 15:26:43'

select Money=sum(money),Dates = convert(varchar(10),dates,120) from #A group by convert(varchar(10),dates,120)

/*
Money Dates
----------- ----------
69 2008-01-12
82 2008-01-13
27 2008-01-14
81 2008-01-15
*/
回复
Limpire 2008-03-22
select Money=sum(money),Dates = convert(varchar(10),dates,120) from tableA group by convert(varchar(10),dates,120)
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-03-22 12:26
社区公告
暂无公告