交叉表 的一个问题
问题描述.
这是一个流量统计表.其中h代表小时,state代表状态
state 为1表示一个访问量,为2表示一个cookie 为3表示一个独立的ip
一个独立的IP肯定也是一个独立的cookie
ALTER PROCEDURE dbo.selectTime @tableID int,@userid bigint,@where nvarchar(500)
AS
declare @sql nvarchar(2000)
set @sql='
select h,sum(state) as pv,
sum(case state when 2 then 1 else 0 end) as cookie, '在这边我想不管为2或为3 then都等于1
sum(case state when 3 then 1 else 0 end) as ip
from counter'+cast(@tableID as varchar)+' where userid='+cast(@userid as varchar)+@where+' group by h order by h'
execute sp_executesql @sql