江湖急救!!!!!!!
SQL 代码如下!
declare @dateTime datetime
declare @startTime datetime
declare @endTime datetime
declare @wname nvarchar(100) --由于你定义的变量长度不够,会导致下面赋值时,值被截断
set @dateTime='2013-11-13'
set @wname='www.baidu.com' --nvarchar时,值会被截断
set @startTime=convert(char(4),datepart(yyyy,@dateTime))+'-01-01'
set @endTime=dateadd(yyyy,1,@startTime)
--这里group by和select中的必须要一样
select sum(readCount) as readtotal,
convert(char(7),comdatetime,20)+'-01' as payt
from WebUserFrom
where webFrom=@wname and comdatetime<@endTime and comdatetime>@startTime
group by convert(char(7),comdatetime,20)+'-01' --这里group by和select中的必须要一样