CSDN博客

img duwx

判断一段时间内连续工作超过7天的纪录

发表于2004/10/13 16:03:00  853人阅读

if EXISTS (
  select * from dbo.sysobjects
  where id = object_id(N'[dbo].[CheckTime]')
  and OBJECTPROPERTY(id, N'IsUserTable') = 1
   )
drop table [dbo].[CheckTime]
GO

CREATE 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 Name
FROM CheckTime as x
WHERE
DATEDIFF(DAY,'2001-1-1',Dates) >= 0 and DATEDIFF(DAY,'2004-1-31',Dates) <= 0
AND
(SELECT COUNT(DISTINCT Dates) FROM CheckTime
 WHERE dates BETWEEN x.dates AND DATEADD(DAY, 6, x.dates)
and Name=x.Name)>=7


(本文章从CSDN上摘录)

阅读全文
0 0

相关文章推荐

img
取 消
img