Statistics are collected by date: hour: Day: Month: Year.

Source: Internet
Author: User

Create proc [DBO]. tongjixinxi
@ Keywordid int,
@ Type Int = 0 -- 0: Day-4, 8, 12, 16, 20, 24
-- 1: Week-1, 2, 3, 4, 5, 6, 7
-- 2: month-5, 10, 15, 20, 25, Di
-- 3: year-3, 6, 9, 12

-- @ Totalinfo int output
As
Begin
Declare @ pagetemp1 table
(
PID int,
Keywordid int,
Title varchar (255 ),
Brief varchar (255 ),
Link varchar (255 ),
Createddate datetime,
Lastupdateddate datetime
)
Declare @ pagetemp2 table
(
PID int,
Keywordid int,
Title varchar (255 ),
Brief varchar (255 ),
Link varchar (255 ),
Createddate datetime,
Lastupdateddate datetime
)
Insert into @ pagetemp1 select P. ID, T. keywordid, T. title, P. brief, P. link, P. createddate, P. lastupdateddate from pagesnaptitles t inner join pagesnaps P on T. id = P. titleid where T. keywordid = @ keywordid
If (@ type = 0) -- 0: Day-4, 8, 12, 16, 20, 24 ---- Note: This is for test use; and other projects are completed; you can delete the formal use of this stored procedure;
Begin
Declare @ num int
Select @ num = count (*) from pagesnaps where day (lastupdateddate) = Day (getdate ()-1
If (@ num> 3)
Begin
Select datepart (hour, T. lastupdateddate) as 'date', count (T. PID) as pscount from
(Select * From @ pagetemp1 where datepart (hour, lastupdateddate)
Between datepart (hour, getdate () and datepart (hour, getdate ()-24) as t
Group by datepart (hour, lastupdateddate)
Order by datepart (hour, lastupdateddate) ASC
End
Else
Begin
Select datepart (hour, lastupdateddate) as 'date', count (*) as pscount from @ pagetemp1 group by datepart (hour, lastupdateddate) order by datepart (hour, lastupdateddate) ASC
End
End
Else if (@ type = 1) ----- 1: Week-1, 2, 3, 4, 5, 6, 7
Begin
Select datename (weekday, T. lastupdateddate) as 'date', count (T. PID) as pscount
From (select * From @ pagetemp1 where datepart (Week, lastupdateddate)
Between datepart (Week, getdate () and datepart (Week, getdate () + 1) as t ---- to verify the data to be modified
Group by datename (weekday, T. lastupdateddate) order by datename (weekday, T. lastupdateddate)
ASC
End
Else if (@ type = 2) -- 2: month-5, 10, 15, 20, 25, Di
Begin
Select convert (varchar (10), lastupdateddate, 120) as 'date', count (PID) as pscount from @ pagetemp1
Group by convert (varchar (10), lastupdateddate, 120)
Order by convert (varchar (10), lastupdateddate, 120) ASC
End
Else if (@ type = 3) -- 3: year-3, 6, 9, 12
Begin
Select datename (year, T. lastupdateddate) as 'date', count (T. PID) as pscount from
(Select * From @ pagetemp1 where year (lastupdateddate)
Between year (dateadd (year,-10, getdate () and year (getdate () as T group
Datename (year, T. lastupdateddate) order by datename (year, T. lastupdateddate) ASC
End
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.