34,835
社区成员




declare @YM nvarchar(10) --求单月的
set @YM='2010-09'
select sum(成交额)as @YM from #TP where convert(nvarchar(7),时间,120)=@YM
declare @Y nvarchar(4) --求一年中12个月分组的
set @Y='2010'
select convert(nvarchar(7),时间,120) as 月份, sum(成交额) as [SUM] from #TP where convert(nvarchar(4),时间,120)=@Y
group by convert(nvarchar(7),时间,120)
select sum(money) as 总成交额 from money where time between '2011-03-18 00:00:00' and '2011-03-19 00:00:00'
select convert(varchar(10),[time],120) [天],sum([money]) [money],
(select sum([money]) from tb where convert(varchar(7),[time],120) = convert(varchar(7),t.[time],120)) [月]
from tb t
group by convert(varchar(10),[time],120)
select convert(varchar(10),[time],120) [天],sum([money]) [money],
(select sum([money]) from tb where convert(varchar(7),[time],120) = convert(varchar(7),t.[time],120)) [月]
from tb t
group by convert(varchar(10),[time],120)
--按天
select convert(varchar(10),[Time],120) as 日期,sum([money]) from tb group by convert(varchar(10),[Time],120)
--按月
select month([time]) as 月,sum([money]) from tb where year([time])=2010 group by month([time])