考勤統計情況SQL語句

2021-04-02 14:04:33 字數 467 閱讀 999

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 0 end ) as 遲到數,

sum(case when eventtype=3 then 1 else 0 end ) as 早退數,

sum(case when eventtype=4 then 1 else 0 end ) as 出差數

from record

where occurred_date between '開始時間' and '結束時間'

group by employeeid,convert(varchar(10),occurred_date,120)

SQL語句 統計

統計某年每個月的資料資訊 如何時間欄位為int型別的秒數,mysql用 例如 select hour from unixtime posttime u as hourtime,year from unixtime posttime u as yeartime,count businessid as ...

統計報表 sql統計語句

需要資料統計頁面,肯定需要匯出資料,於是,邊學邊寫,完成了一段sql 最早的版本是這樣的 分三條sql查出三種不同的狀態的記錄數 總記錄,未支付,已支付 select count as recordcount from t record where createtime 2019 01 01 00 ...

SQL統計語句技巧

select t.t.rowid from ts orders t select from ts cust 查詢 type 0 1 的訂單數 select count o.oid as 總訂單數 count o1.oid as type1 訂單總數 count o2.oid as type0 訂單總...

SQL語句 分組統計

一 教師號 星期號 是否有課 有 有 有 有 有 寫一條sql語句讓你變為這樣的表 教師號 星期一 星期二 星期三 各星期下的數字表示 對應的教師在星期幾已經排的課數 答案是 select 教師號 sum case when 星期號 1then 是否有課 else 0end as 星期一 sum c...

group by分組統計SQL語句

用一條查詢語句,查出各姓名的數值餘額.使用者表 姓名a bc 扣費表 姓名 數值 a 3.5 b 5.2 a 2.充值表 姓名 數值 b 10 a 10 a 10.5 返回 姓名 差額 充值和 扣費和 測試通過 select table1.tname,table1.telname,table3.充值...