溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

按某一列里面同一類橫向顯示數(shù)據(jù)總數(shù)

發(fā)布時(shí)間:2020-03-04 10:22:50 來源:網(wǎng)絡(luò) 閱讀:260 作者:重命名 欄目:關(guān)系型數(shù)據(jù)庫

如下圖,統(tǒng)計(jì)某一時(shí)間段請(qǐng)假類別為Kj_tx 積休假、Kj_nj年假的天數(shù)綜合 并按列顯示

select?
a.AlEmpID as 員工ID,
a.alsdate,
a.aledate,
AlTime=(
case when a.ALSTime=480 and a.ALETime=1050 then 1?
? ? ?when a.ALSTime=480 and a.ALETime=720? then 0.5?
? ? ?when a.ALSTime=840? and a.ALETime=1050 then 0.5?
? ? ?when a.ALSTime=870? and a.ALETime=1050 then 0.5?
? ? ? else 0 end) ,
a.ALFType as 請(qǐng)假類別
from? kq_askleave a?
where a.AlEmpID=734 and a.alsdate>='2018-03-01 00:00:00'

按某一列里面同一類橫向顯示數(shù)據(jù)總數(shù)


select?
aa.員工ID,
max(d.Dept_lname) as 科室,
max(b.Emp_code) as 工號(hào),
max(b.Emp_name) as 姓名,
max(b.Emp_zhiweiname) as 職位,
isnull(sum(case when? aa.請(qǐng)假類別 ='Kj_nj' then aa.AlTime+AlDay end ),0) 年假,
isnull(sum(case when? aa.請(qǐng)假類別 ='Kj_sj' then aa.AlTime+AlDay end ),0) 事假,
isnull(sum(case when? aa.請(qǐng)假類別 ='Kj_bj' then aa.AlTime+AlDay end ),0) 病假,
isnull(sum(case when? aa.請(qǐng)假類別 ='Kj_cj' then aa.AlTime+AlDay end ),0) 產(chǎn)假,
isnull(sum(case when? aa.請(qǐng)假類別 ='Kj_hj' then aa.AlTime+AlDay end ),0) 婚假,
isnull(sum(case when? aa.請(qǐng)假類別 ='Kj_tx' then aa.AlTime+AlDay end ),0) 積休假
from?
(select?
a.AlEmpID as 員工ID,
a.alsdate,
a.aledate,
AlDay=(
case when a.ALSTime=480 and a.ALETime=1050? then datediff(day,a.alsdate,a.aledate)+1?
? ? ?when a.ALSTime=480 and a.ALETime=720? then? datediff(day,a.alsdate,a.aledate)
? ? ?when a.ALSTime=840? and a.ALETime=1050 then datediff(day,a.alsdate,a.aledate)?
? ? ?when a.ALSTime=870? and a.ALETime=1050 then datediff(day,a.alsdate,a.aledate)?
? ? ? else 0 end) ,
AlTime=(
case when a.ALSTime=480 and a.ALETime=1050 then 0?
? ? ?when a.ALSTime=480 and a.ALETime=720? then 0.5?
? ? ?when a.ALSTime=840? and a.ALETime=1050 then 0.5?
? ? ?when a.ALSTime=870? and a.ALETime=1050 then 0.5?
? ? ? else 0 end) ,


a.ALFType as 請(qǐng)假類別
from? kq_askleave a?
where a.AlEmpID=734 and a.alsdate>='2016-11-01 00:00:00' and a.aledate<='2018-05-01 00:00:00') aa
left join employeeview b on aa.員工ID=b.emp_id?
left join kq_altype c on aa.請(qǐng)假類別=c.kqaltcode?
left join emp_department d on b.Dept_code=d.Dept_code
group by? aa.員工ID


按某一列里面同一類橫向顯示數(shù)據(jù)總數(shù)

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI