22,206
社区成员
发帖
与我相关
我的任务
分享
select Num,Time from
(select count(Time) as Num ,(convert(varchar(30),Time,23)) as Time from Info
where From ='Ba'
and Time between DateAdd("ww",-1,getdate()) and getdate()
Group by (convert(varchar(30),Time,23))) as table1
declare @sql varchar(max)
select count(Time) as Num ,(convert(varchar(30),Time,23)) as Time
into #t
from Info
where From ='Ba'
and Time between DateAdd("ww",-1,getdate()) and getdate()
Group by (convert(varchar(30),Time,23))
select @sql = isnull(@sql + ',','') + '(case time when ''' + time + ''' then num else 0 end)[' + time + ']'
from (select distinct time from #t)t
exec('select ' + @sql + ' from #t')
drop table #t
select
max(case VisitTime when '2011-03-06' then num end) as '2011-03-06' ,
max(case VisitTime when '2011-03-07' then num end) as '2011-03-07',
max(case VisitTime when '2011-03-09' then num end) as '2011-03-09'
from sdf1
declare @sql varchar(max)
select count(Time) as Num ,(convert(varchar(30),Time,23)) as Time
into #t
from Info
where From ='Ba'
and Time between DateAdd("ww",-1,getdate()) and getdate()
Group by (convert(varchar(30),Time,23))
select @sql = isnull(@sql + ',','') + ',(case time when ''' + time + ''' then num else 0 end)[' + time + ']'
from (select distinct time from #t)t
exec('select ' + @sql + ' from #t')