AccessLog200606(log日志表)
 其中,isdown表示浏览(1)下载(2),
 itype表示浏览素材类型id,
 uid是用户id,
 tier是用户性别年龄段,如04_1表示30-35岁 男
id month isdown itype tid bid nid uid tier ua views ntime
1 200606 1 1 1 2 0 301462 10_0 NEC-N8202 1 2006-06-08 13:55:21.747
2 200606 1 1 1 73 0 301463 04_1 NEC-N700 1 2006-06-08 13:55:42.247
stat_d_tbl(统计数据表)
其中,folder表示浏览素材类型,同上表中的itype
type对应于上表的isdown,表示浏览(1)下载(2)
userAgent对应于上表的ua,用户使用的机型
tier对应于上表的tier,表示性别年龄段
userNum是浏览总数
uniqueNum是不重复访问用户数theDate folder type userAgent userNum uniqueNum tier
2005-07-21 00:00:00 6 2 NEC-N810 242 35 09_1
2005-07-21 00:00:00 2 2 NEC-N820 21 5 02_1
现在是把每个月的log放在一张分区表里,表名如:AccessLogYYYYMM由于要跨月统计,所以通过如下的存储过程将相关记录导入到统计表中
建立存贮过程如下:--统计前一天,每种类型,每个年龄段,男、女---点击数,单独用户数
alter procedure GetStatDayly
@days varchar(10)
asset nocount ondeclare @sql varchar(8000)
declare @month varchar(10)
declare @AccessLogTable varchar(50)
declare @statTable varchar(50)
declare @memberTable varchar(50)set @month = convert(varchar(6),getdate(),112)
if (day(getdate())=1)
set @month = convert(varchar(6),dateadd(dd,-1,getdate()),112)
set @AccessLogTable = 'NEC_CN..AccessLog'+@month
--set @AccessLogTable = 'NEC_CN..AccessLog200606'
set @statTable = 'NEC_CN..stat_d_tbl'
set @sql = '
insert ' + @statTable + ' (theDate,folder,userAgent,tier,type,userNum,uniqueNum) 
select convert(varchar(10),ntime,120),
itype,A.ua,
tier,
isdown,
sum(views),
count(distinct uid)
from ' + @AccessLogTable + ' A 
where datediff(dd,ntime,getdate()) = ' + @days + '
group by 
convert(varchar(10),ntime,120),
itype,
A.ua,
tier,
isdown'
set @sql = 'if not exists(select top 1 folder from ' + @statTable + ' where datediff(dd,theDate,getdate())='+ @days +') begin ' + @sql
set @sql = @sql + ' end'
--print @sql
begin tran
exec (@sql)
if (@@error = 0 and @@trancount>0)
commit tran
else
rollback tranGO每天通过作业如下调用:
exec GetStatDayly '1'当数据进入到stat_d_tbl后,和原来的log表对比发现
假设从2006-6-13开始--访问量
select sum(usernum)  from stat_d_tbl where thedate >= '2006-6-13' and type=1 
结果:361148select sum(views)  from AccessLog200606 where ntime >= '2006-6-13' and isdown=1
group by convert(varchar(10),ntime,120)
对分组结果合计后数据为:361148对比发现,访问量没有问题。--用户访问量
select sum(uniqueNum)  from stat_d_tbl where thedate >= '2006-6-13' and type=1 
结果:53836select count(distinct uid)  from AccessLog200606 where ntime >= '2006-6-13' and isdown=1
group by convert(varchar(10),ntime,120)
对分组结果合计后数据为:15448对比发现:数据不符请问是哪里的问题?

解决方案 »

  1.   

    没有细看,不过你的2个查询应该是不一样的
    select sum(uniqueNum)  from stat_d_tbl where thedate >= '2006-6-13' and type=1 
    结果:53836 
    ---这个是把每天的独立ID加起来
    select count(distinct uid)  from AccessLog200606 where ntime >= '2006-6-13' and isdown=1
    group by convert(varchar(10),ntime,120)
    对分组结果合计后数据为:15448
    --这个是真实的ID数
    希望对你有帮助