首页 新闻 会员 周边

通过输入时间段,查询出勤率,迟到次数,早退次数,旷工次数,用的ssh集成,oracle数据库,怎么写查询方法

0
悬赏园豆:100 [已关闭问题] 关闭于 2012-02-14 16:43

manualsign 考勤信息表

ms_id int 非空 种子,自增1 签卡Id  

user_id Varchar(50) 非空 表UserInfo中userid的外键 用户id

ms_time DateTime 非空 签卡时间

ms_desc Varchar(200) 非空 签卡备注

ms_tag int 非空 签卡标记  (1,上班打卡,0,下班打卡)

tbl_worktime 上下班时间表

wt_id int 非空 种子,自增1 工作时间Id

wt_uptime Varchar(50) 非空 上班时间

wt_downtime Varchar(50) 非空 下班时间 

工作时间固定值  
工作日按常规计算 早9:00 晚18:00
要跟据页面上面输入的开始时间和结束时间 查询出出勤率,迟到次数,早退次数,旷工次数
问题补充:

文艺冰的主页 文艺冰 | 初学一级 | 园豆:87
提问于:2012-02-13 14:34
< >
分享
所有回答(2)
0

很多人都很喜欢写sql的,不过最好你能每个table中举几条示例数据

LCM | 园豆:6876 (大侠五级) | 2012-02-13 14:44
0

每个数据单独一个 SQL 比较好写,如果整个的一个 SQL 查出所有数据,就不是一般的难。

以下 SQL 未经严格测试,且有前提条件:每天每个人只能上班打卡一次。

 

出勤率 = 上班打卡次数/工作日数 , 这个需要测试,应该还需要关联用户表。
(select count(*)  from manualsign s where ms_time> ? and ms_time < ? )
 /(select count(*)  from tbl_worktime w2 where wt_uptime> ? and wt_uptime < ?)

迟到次数 = "上班打卡时间"在同一天的"上班时间" 之前
 select count(*) from manualsign s
 where exists(select 1 from tbl_worktime w where to_char(s.ms_time,'yyyymmdd') = to_char(w.wt_uptime,'yyyymmdd')
 and s.ms_time < w.wt_uptime
 and wt_uptime> ? and wt_uptime < ?
 )
 and s.ms_tag = 1
 and ms_time> ? and ms_time < ?
 

早退次数 = "下班打卡时间"在同一天的"下班时间" 之前
 select count(*) from manualsign s
 where exists(select 1 from tbl_worktime w where to_char(s.ms_time,'yyyymmdd') = to_char(w.wt_uptime,'yyyymmdd')
 and s.ms_time < w.wt_downtime
 and wt_uptime> ? and wt_uptime < ?
 )
 and s.ms_tag = 0
 and ms_time> ? and ms_time < ?

旷工次数 = 工作日中无上班打卡的次数,应该还需要关联用户表。
 select count(*) from tbl_worktime w
 where wt_uptime> ? and wt_uptime < ?
 and not exists(select 1 from manualsign s where to_char(s.ms_time,'yyyymmdd') = to_char(w.wt_uptime,'yyyymmdd')  )

杰克伦敦尘 | 园豆:274 (菜鸟二级) | 2012-02-14 13:24

补充,如果  tbl_worktime  是每天一行数据中,既有过去时间的上下班,也有未来几天的上下班,还应该加上 where 条件 wt_uptime < 当前时间。

当然,如果 tbl_worktime 不是每天一行数据,那么上述 SQL 都不能这么写。

支持(0) 反对(0) 杰克伦敦尘 | 园豆:274 (菜鸟二级) | 2012-02-16 13:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册