页面 PV 按照 年 月 日 小时 统计 的存储过程
发布时间:2020-05-23 09:38:11 所属栏目:MySql 来源:互联网
导读:页面 PV 按照 年 月 日 小时 统计 的存储过程
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 -- ============================================= -- 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][emailprotected] and [Y] = @Y and [M][emailprotected] and [D][emailprotected] 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][emailprotected] and [D][emailprotected] and [H] = @H; --Y M D select @NowDayTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y and [M][emailprotected] and [D][emailprotected]; --Y W select @NowWeekTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y and [W][emailprotected]; --Y M select @NowMonthTimes = SUM([Times]) from [PV] where ChannelID = @ChannelID and SourceID = @SourceID and [Y] = @Y and [M][emailprotected]; --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,@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,@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,@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],[HourRate],[HourTimes],[DayRate],[DayTimes],[WeekRate],[WeekTimes],[MonthRate],[MonthTimes],[YearRate],[YearTimes],[Total]) Values(@ChannelID,@HourRate,@NowHourTimes,@DayRate,@NowDayTimes,@WeekRate,@NowWeekTimes,@MonthRate,@NowMonthTimes,@YearRate,@NowYearTimes,@Total); else Update [PVS] set [HourRate][emailprotected],[HourTimes][emailprotected],[DayRate][emailprotected],[DayTimes][emailprotected],[WeekRate][emailprotected],[WeekTimes][emailprotected],[MonthRate][emailprotected],[MonthTimes][emailprotected],[YearRate][emailprotected],[YearTimes][emailprotected],[Total][emailprotected] where ID = @TempID; end GO 以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- MySQL数据库从远程主机转储而没有临时文件
- java – 使用Eclipse Link在JPA中映射Joda Time“Period”的
- MySQL查询在phpMyAdmin中工作,在PHP中失败
- MYSQL教程修改mysql允许主机访问的权限方法
- PHP或MySQL中的业务逻辑?
- php – mysql:在每个连接上设置NAMES utf8?
- Java JDBC MySQL异常:“ResultSet关闭后不允许操作”
- MYSQL教程MySQL中group_concat函数深入理解
- MYSQL数据库ubuntu下设置mysql自动备份的例子
- Running only a subset of the tests
