页面 PV 按照 年 月 日 小时 统计 的存储过程
需求:需要做一个统计 网站是这样的:网站上有 视频频道、图片频道、新闻频道等 需要做一个统计,能够统计这几个频道 中每个资源 某个小时、 某天、某周、某月、某年、总的 访问的次数 从上述需求看,只要统计每个资源,一天24 个小时的访问量 然后分类汇总就
需求:需要做一个统计网站是这样的:网站上有 视频频道、图片频道、新闻频道 等
需要做一个统计,能够统计这几个频道 中每个资源 某个小时、 某天、某周、某月、某年、总的 访问的次数
从上述需求看,只要统计每个资源,一天24 个小时的访问量 然后分类汇总就可以 算出 某天、某周、某月、某年、总的 范围的次数
原理就是这样。
表结构如下:
[Channel] 频道表
ID
Name //频道名称
[Video] 视频表
ID
...
[Photo] 图库表
ID
...
[News] 新闻表
ID
...
存储过程用了下面的两张表详细的写下:
[PV] 表
[ID] [int] IDENTITY(1,1) NOT NULL, [ChannelID] [int] NOT NULL,//频道ID [SourceID] [int] NOT NULL,//源ID [Times] [int] NOT NULL,//次数 [Y] [smallint] NULL,//年 如 2000 [M] [tinyint] NULL,//月 如 12 [W] [tinyint] NULL,//周 如 50 [D] [tinyint] NULL,//日 如 21 [H] [tinyint] NULL//小时 如 16
[PVS] 汇总结果表 [ID] [int] IDENTITY(1,1) NOT NULL, [ChannelID] [int] NOT NULL,//频道ID [SourceID] [int] NOT NULL,//源ID [HourRate] [float] NULL,//当前小时与上个小时相比上升的速率 [HourTimes] [int] NULL,//当前小时访问的次数 [DayRate] [float] NULL,//今天与昨天相比上升的速率 [DayTimes] [int] NULL,//今天访问的次数 [WeekRate] [float] NULL,//当周与上周相比上升的速率 [WeekTimes] [int] NULL,//当周访问的次数 [MonthRate] [float] NULL,//当月与上月相比上升的速率 [MonthTimes] [int] NULL,//当周访问的次数 [YearRate] [float] NULL,//今年与上一年相比上升的速率 [YearTimes] [int] NULL,//今年访问的次数 [Total] [int] NULL//访问的总次数
<无>
-- ============================================= -- Author: <Author,FHZ,> -- Create date: <Create Date,2011-11-25 15:55,> -- Description: <Description,更新统计信息,> -- ============================================= CREATE proc [dbo].[procCountPV]( @ChannelID nvarchar(50), @SourceID int ) as begin declare @TEMID int; --临时ID declare @Now datetime; set @Now = GETDATE(); declare @Y smallint;--年 declare @M tinyint;--月 declare @W tinyint;--周 declare @D tinyint;--日 declare @H tinyint;--小时 set @Y = DATEPART(YY,@Now); set @M = DATEPART(MM,@Now); set @W = DATEPART(WW,@Now); set @D = DATEPART(DD,@Now); set @H = DATEPART(HH,@Now); select @TEMID = [ID] from [PV] where [ChannelID] = @ChannelID and [SourceID]=@SourceID and [Y] = @Y and [M]=@M and [D]=@D and [H] = @H; if @TEMID is null Insert into [PV]([ChannelID],[SourceID],[Times],[Y],[M],[W],[D],[H]) values(@ChannelID ,@SourceID,1,@Y,@M,@W,@D,@H); else Update [PV] set [Times] = [Times]+1 where [ID]= @TEMID; /*计算现在*/ Declare @NowHourTimes int; Declare @NowDayTimes int; Declare @NowWeekTimes int; Declare @NowMonthTimes int; Declare @NowYearTimes int; --Y M D H select @NowHourTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y and [M]=@M and [D]=@D and [H] = @H; --Y M D select @NowDayTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y and [M]=@M and [D]=@D; --Y W select @NowWeekTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y and [W]=@W; --Y M select @NowMonthTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y and [M]=@M; --Y select @NowYearTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y; if @NowHourTimes is null set @NowHourTimes = 0; if @NowDayTimes is null set @NowDayTimes = 0; if @NowWeekTimes is null set @NowWeekTimes = 0; if @NowMonthTimes is null set @NowMonthTimes = 0; if @NowYearTimes is null set @NowYearTimes = 0; /*计算之前*/ Declare @PreHourTimes int; Declare @PreDayTimes int; Declare @PreWeekTimes int; Declare @PreMonthTimes int; Declare @PreYearTimes int; --Y M D H Declare @PreHourDateTime datetime; set @PreHourDateTime = DATEADD(HH,-1,@Now); select @PreHourTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = DATEPART(YY,@PreHourDateTime) and [M]=DATEPART(MM,@PreHourDateTime) and [D]=DATEPART(DD,@PreHourDateTime) and [H] = DATEPART(HH,@PreHourDateTime); --Y M D Declare @PreDayDateTime datetime; set @PreDayDateTime = DATEADD(DD,-1,@Now); select @PreDayTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = DATEPART(YY,@PreDayDateTime) and [M]=DATEPART(MM,@PreDayDateTime) and [D]=DATEPART(DD,@PreDayDateTime); --Y W Declare @PreWeekDateTime datetime; set @PreWeekDateTime = DATEADD(WW,-1,@Now); select @PreWeekTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = DATEPART(YY,@PreWeekDateTime) and [W]= DATEPART(WW,@PreWeekDateTime); --Y M Declare @PreMonthDateTime datetime; set @PreMonthDateTime = DATEADD(MM,-1,@Now); select @PreMonthTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = DATEPART(YY,@PreMonthDateTime) and [M]= DATEPART(MM,@PreMonthDateTime); --Y select @PreYearTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y - 1; if @PreHourTimes is null set @PreHourTimes = 0; if @PreDayTimes is null set @PreDayTimes = 0; if @PreWeekTimes is null set @PreWeekTimes = 0; if @PreMonthTimes is null set @PreMonthTimes = 0; if @PreYearTimes is null set @PreYearTimes = 0; declare @HourRate float; declare @DayRate float; declare @WeekRate float; declare @MonthRate float; declare @YearRate float; set @HourRate = 0; set @DayRate = 0; set @WeekRate = 0; set @MonthRate = 0; set @YearRate = 0; if @PreHourTimes > 0 set @HourRate = ( @NowHourTimes - @PreHourTimes )/ (@PreHourTimes+0.0); if @PreDayTimes > 0 set @DayRate = ( @NowDayTimes - @PreDayTimes )/ (@PreDayTimes+0.0); if @PreWeekTimes > 0 set @WeekRate = ( @NowWeekTimes - @PreWeekTimes )/ (@PreWeekTimes+0.0); if @PreMonthTimes > 0 set @MonthRate = ( @NowMonthTimes - @PreMonthTimes )/ (@PreMonthTimes+0.0); if @PreYearTimes > 0 set @YearRate = ( @NowYearTimes - @PreYearTimes )/ (@PreYearTimes+0.0); /*计算总量*/ declare @Total int; select @Total = SUM([Times]) From [PV] where ChannelID = @ChannelID and SourceID = @SourceID; if @Total is null set @Total = 0; declare @TempID int; set @TempID = null; /*操作CountSummary*/ Select @TempID = ID from [PVS] where ChannelID = @ChannelID and SourceID = @SourceID; if @TempID is null Insert into [PVS]([ChannelID],[SourceID],[HourRate],[HourTimes],[DayRate],[DayTimes],[WeekRate],[WeekTimes],[MonthRate],[MonthTimes],[YearRate],[YearTimes],[Total]) Values(@ChannelID,@SourceID,@HourRate,@NowHourTimes,@DayRate,@NowDayTimes,@WeekRate,@NowWeekTimes,@MonthRate,@NowMonthTimes,@YearRate,@NowYearTimes,@Total); else Update [PVS] set [HourRate]=@HourRate,[HourTimes]=@NowHourTimes,[DayRate]=@DayRate,[DayTimes]=@NowDayTimes,[WeekRate]=@WeekRate,[WeekTimes]=@NowWeekTimes,[MonthRate]=@MonthRate,[MonthTimes]=@NowMonthTimes,[YearRate]=@YearRate,[YearTimes]=@NowYearTimes,[Total]=@Total where ID = @TempID; end GO
CREATE TABLE [dbo].[PV]( [ID] [int] IDENTITY(1,1) NOT NULL, [ChannelID] [int] NOT NULL, [SourceID] [int] NOT NULL, [Times] [int] NOT NULL, [Y] [smallint] NULL, [M] [tinyint] NULL, [W] [tinyint] NULL, [D] [tinyint] NULL, [H] [tinyint] NULL, CONSTRAINT [PK_PV] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[PV] ADD CONSTRAINT [DF_PV_Times] DEFAULT ((0)) FOR [Times] GO ALTER TABLE [dbo].[PV] ADD CONSTRAINT [DF_PV_Y] DEFAULT ((2000)) FOR [Y] GO ALTER TABLE [dbo].[PV] ADD CONSTRAINT [DF_PV_M] DEFAULT ((1)) FOR [M] GO ALTER TABLE [dbo].[PV] ADD CONSTRAINT [DF_PV_W] DEFAULT ((1)) FOR [W] GO ALTER TABLE [dbo].[PV] ADD CONSTRAINT [DF_PV_D] DEFAULT ((1)) FOR [D] GO ALTER TABLE [dbo].[PV] ADD CONSTRAINT [DF_PV_H] DEFAULT ((0)) FOR [H] GO
CREATE TABLE [dbo].[PVS]( [ID] [int] IDENTITY(1,1) NOT NULL, [ChannelID] [int] NOT NULL, [SourceID] [int] NOT NULL, [HourRate] [float] NULL, [HourTimes] [int] NULL, [DayRate] [float] NULL, [DayTimes] [int] NULL, [WeekRate] [float] NULL, [WeekTimes] [int] NULL, [MonthRate] [float] NULL, [MonthTimes] [int] NULL, [YearRate] [float] NULL, [YearTimes] [int] NULL, [Total] [int] NULL, CONSTRAINT [PK_PVS] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

是否要复制MicrosoftWord中的页面,并保持格式不变?这是一个聪明的想法,因为当您想要创建特定文档布局或格式的多个副本时,在Word中复制页面可能是一种有用的节省时间的技术。本指南将逐步引导您在Word中复制页面的过程,无论是创建模板还是复制文档中的特定页面。这些简单的说明旨在帮助您轻松地重新制作页面,省去从头开始的麻烦。为什么要在MicrosoftWord中复制页面?在Word中复制页面非常有益的原因有以下几点:当您有一个具有特定布局或格式的文档要复制时。与从头开始重新创建整个页面不同

本站3月7日消息,华为数据存储产品线总裁周跃峰博士日前出席MWC2024大会,专门展示了为温数据(WarmData)和冷数据(ColdData)设计的新一代OceanStorArctic磁电存储解决方案。华为数据存储产品线总裁周跃峰发布系列创新解决方案图源:华为本站附上华为官方新闻稿内容如下:该方案的成本比磁带低20%,功耗比硬盘低90%。根据国外科技媒体blocksandfiles报道,华为发言人还透露了关于该磁电存储解决方案的信息:华为的磁电磁盘(MED)是对磁存储介质的重大创新。第一代ME

Vue3+TS+Vite开发技巧:如何进行数据加密和存储随着互联网技术的快速发展,数据的安全性和隐私保护变得越来越重要。在Vue3+TS+Vite开发环境下,如何进行数据加密和存储,是每个开发人员都需要面对的问题。本文将介绍一些常用的数据加密和存储的技巧,帮助开发人员提升应用的安全性和用户体验。一、数据加密前端数据加密前端加密是保护数据安全性的重要一环。常用

电子邮件签名对于展示合法性和专业性非常重要,其中包括联系信息和公司标志。Outlook用户经常抱怨签名在重启后会消失,这对于那些希望提高公司知名度的人来说可能会很沮丧。在本文中,我们将探讨不同的修复程序,以解决这一问题。为什么我的MicrosoftOutlook签名总是消失?如果您第一次使用MicrosoftOutlook,请确保您的版本不是试用版。试用版可能导致签名消失。此外,版本体系结构也应与操作系统的版本体系结构匹配。如果您发现OutlookWeb应用程序中的电子邮件签名不时消失,可能是因

如何在uniapp中实现数据统计和分析一、背景介绍数据统计和分析是移动应用开发过程中非常重要的一环,通过对用户行为的统计和分析,开发者可以深入了解用户的喜好和使用习惯,从而优化产品设计和用户体验。本文将介绍如何在uniapp中实现数据统计和分析的功能,并提供一些具体的代码示例。二、选择合适的数据统计和分析工具在uniapp中实现数据统计和分析的第一步是选择合

如何使用SQL语句在MySQL中进行数据聚合和统计?在进行数据分析和统计时,数据聚合和统计是非常重要的步骤。MySQL作为一个功能强大的关系型数据库管理系统,提供了丰富的聚合和统计函数,可以很方便地进行数据聚合和统计操作。本文将介绍使用SQL语句在MySQL中进行数据聚合和统计的方法,并提供具体的代码示例。一、使用COUNT函数进行计数COUNT函数是最常用

《处理Laravel页面无法正确显示CSS的方法,需要具体代码示例》在使用Laravel框架开发Web应用时,有时候会遇到页面无法正确显示CSS样式的问题,这可能会导致页面呈现不正常的样式,影响用户体验。本文将介绍一些处理Laravel页面无法正确显示CSS的方法,并提供具体的代码示例,帮助开发者解决这一常见问题。一、检查文件路径首先要检查CSS文件的路径是

标题:3秒跳转页面实现方法:PHP编程指南在网页开发中,页面跳转是常见的操作,一般情况下我们使用HTML中的meta标签或者JavaScript的方法进行页面跳转。不过,在某些特定的情况下,我们需要在服务器端进行页面跳转。本文将介绍如何使用PHP编程实现一个在3秒内自动跳转到指定页面的功能,同时会给出具体的代码示例。PHP实现页面跳转的基本原理PHP是一种在
