请教统计每天销售
销售时间 销售额
2007-08-25 08:25:00 120.00
2007-08-25 08:30:00 130.00
2007-08-25 10:00:00 110.00
2007-08-26 09:00:00 90.00
2007-08-26 10:11:00 100.00
2007-08-26 11:12:00 110.00
2007-08-31 14:00:00 200.00
2007-08-31 15:00:00 210.00
2007-08-31 16:00:00 230.00
统计后的结果
日期 每天销售
2007-08-25 360.00
2007-08-26 300.00
2007-08-31 640.00
------解决方案--------------------Select
Convert(varchar(10),销售时间,120) As 日期,
Sum(销售额) As 每天销售
From TableName
Group By Convert(varchar(10),销售时间,120)
------解决方案--------------------select convert(varchar(10),销售时间 ,120) 销售时间 , sum(销售额) 每天销售
from tb
group by convert(varchar(10),销售时间 ,120)
------解决方案--------------------select
日期=convert(varchar(10),销售时间,120),
每天销售=sum(销售额)
from 表
group by convert(varchar(10),销售时间,120)
------解决方案-----------------------创建测试环境
Declare @T Table(销售时间 datetime,销售额 decimal(8,2))
Insert @T Select '2007-08-25 08:25:00 ', 120.00
Union All Select '2007-08-25 08:30:00 ', 130.00
Union All Select '2007-08-25 10:00:00 ', 110.00
Union All Select '2007-08-26 09:00:00 ', 90.00
Union All Select '2007-08-26 10:11:00 ', 100.00
Union All Select '2007-08-26 11:12:00 ', 110.00
Union All Select '2007-08-31 14:00:00 ', 200.00
Union All Select '2007-08-31 15:00:00 ', 210.00
Union All Select '2007-08-31 16:00:00 ', 230.00
---查询结果
Select
Convert(varchar(10),销售时间,120) As 日期,
Sum(销售额) As 每天销售
From
@T
Group By
Convert(varchar(10),销售时间,120)
---结果
/*
日期 每天销售
---------- -----------
2007-08-25 360.00
2007-08-26 300.00
2007-08-31 640.00
(所影响的行数为 3 行)
*/