查询连续N天有考勤记录的数据

查询连续N天有考勤记录的数据


with t
as(
select
px=DATEADD(DD,-ROW_NUMBER()over(partition by Pid
     order by [RDate] asc),[RDate]),
[Pid], [RDate]
from Att_Raw_Data
where [RDate]>'2013-05-01'
group by rdate ,pid

),
m as(
select  [Pid],MIN([RDate]) as StartTime,MAX([RDate]) as EndTime
from t
group by px,[Pid]
)
select [Pid],DATEDIFF(DD,StartTime,EndTime)+1 as 连续天数,StartTime, EndTime
from m
where DATEDIFF(DD,StartTime,EndTime)>=6 --连续六天
order by pid asc,连续天数 desc


结果:


取各分类前三条记录


select *
from HR_EMAGAZINE a
where title in (select top 3 title from HR_EMAGAZINE where Catalog_ID=a.Catalog_ID  order by Catalog_ID asc) order by Catalog_ID asc




[本日志由 admin 于 2013-06-07 08:57 PM 更新]
上一篇: FlashPaper: Pdf转swf 横向页面变纵向页面解决方案
下一篇: 第一个父亲节
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: 考勤记录
相关日志:
评论: 0 | 引用: 0 | 查看次数: 3755
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 30 字 | UBB代码 关闭 | [img]标签 关闭