每日考勤統計

2021-05-26 00:37:52 字數 1332 閱讀 8750

最近 一直在做公司的每日考勤這一塊,用的是mysql 在寫的時候遇到了不少的麻煩 其一在選取有效工作日時(attendance_time 存的是考勤資料,_atte_holidays 這裡面存的是節假日的資料),我用了一條sql語句來查詢 

select distinct(date_format(tt.attendance_time,'%y-%m-%d')) from t_attendance_time tt

where date_format(tt.attendance_time,'%y-%m-%d') between '2011-02-04' and '2011-03-04' and

tt.attendance_time not in(

select distinct(t.attendance_time) from t_attendance_time t,t_atte_holidays th where

date_format(t.attendance_time,'%y-%m-%d') between date_format(th.date_start,'%y-%m-%d') and date_format(th.date_end,'%y-%m-%d') and

date_format(t.attendance_time,'%w') not in ('0','6') )

and date_format(tt.attendance_time,'%w') not in ('0','6')  order by  tt.attendance_time desc

結果是出來了,可這條語句執行起來超慢,受不了。經過我不斷思考 把兩個表並起來查:又寫成了這樣:

select distinct(date_format(tt.attendance_time,'%y-%m-%d')) from t_attendance_time tt,t_atte_holidays th

where date_format(tt.attendance_time,'%y-%m-%d') between '2011-02-04' and '2011-03-04' and

date_format(tt.attendance_time,'%y-%m-%d') not between date_format(th.date_start,'%y-%m-%d') and date_format(th.date_end,'%y-%m-%d')

and date_format(tt.attendance_time,'%w') not in ('0','6')

order by tt.attendance_time desc

我想過了,兩者的查詢結果是一樣的。後者查詢速度是超快的。但對為啥會變快了 還是不太了解 有哪位對資料庫熟悉 請你不吝賜教

考勤名單node統計

名單內容如下 arr每天的缺勤人員統計總數 蔣勇軍 谷昊 李健 賀誌軒 陳廣程 鄧麗欣 comparedata arr lostname lostname.concat lost return lostname 當天的缺勤名單 comparetoday allarr,arr return lost ...

考勤統計情況SQL語句

select employeeid,convert varchar 10 occurred date,120 as 天數,sum case when eventtype 1 then 1 else 0 end as 出勤數,sum case when eventtype 2 then 1 else ...

高校考勤簽到系統php,php實現每日簽到功能

首次簽到獲得1個積分,第二次簽到獲得2個積分,第三次簽到獲得3個積分,以此類推但是簽到必須每天連續積分才可以遞增,如果有中斷再次簽到時獲得積分仍然從1開始遞增 簽到 function datatype json success function res else count 1 point 1 si...