Decree a record for more than 7 days in a period of time

xiaoxiao2021-03-06  84

IF exists (Select * from dbo.sysObjects where id = Object_id (n '[dbo]) and ObjectProperty (ID, n'susertable') = 1) Drop Table [dbo]. [checktime] Go

Crete Table [DBO]. [Checktime] ([Id] [INT] Identity (1, 1) Not Null, [Name] [NVARCHAR] (50) Collate Chinese_PRC_CI_AS NULL, [DATES] [DATETIME] NULL) ON [PRIMARY] Go

Select Distinct NameFrom CheckTime As x Where datediff (day, '2001-1-1', dates)> = 0 and datediff (day, '2004-1-31', dates) <= 0and (SELECT Count (Distinct Dates) from FROM CheckTime WHERE DATES BETWEEN X.DATES AND DATEADD (DAY, 6, X.Dates) and name = x.name)> = 7 (this article excerpts from 9CBS)

转载请注明原文地址:https://www.9cbs.com/read-106941.html

New Post(0)