求一个关于时期的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


...全文
51 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
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)

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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