1. 程式人生 > >自定義列標題 case when

自定義列標題 case when

case bubuko 撤銷 classname time alt inf group 2-0

set@schoolid=41;
select l.StartTime,l.EndTime,c.EntranceYear as 入學級,cg.Grade as 年級,c.ClassName as 班級名稱,
s.CName as 學生,
st.StuNumber as 學號,
case l.LeaveType when 1 then ‘事假‘ when 2 then ‘病假‘ end as 請假類型,
l.Reason as 請假理由,
case l.ApproveStatus when 0 then ‘請假申請中‘ when 1 then ‘審批通過‘
when 2 then ‘審批駁回‘ when 3 then ‘撤銷審批中‘
when 4 then ‘縮假審批中‘ when 5 then ‘已撤銷‘
end as 請假狀態,
o.DisplayName as 審批人,
l.ApproveTime as 審批時間,
l.CreateTime as 審批時間2
from leaverecord l
left join class c on l.ClassId=c.Id
left join studentinfo s on s.id = l.StudentId
LEFT JOIN class_grade cg on cg.ClassId=c.Id
LEFT JOIN orguser o on o.id = l.ApproveOrgUserId
left join stustatusinfo st on st.StuInfoId = s.id
where l.SchoolId=@schoolid#校區
and l.LeaveType=2 #請假類型 1事假 2病假
and l.ApproveStatus=1#0請假申請中 1審批通過 2審批駁回3撤銷審批中4縮假審批中5已撤銷
and c.id=282#班級id
and ((l.EndTime <=‘2017-12-12 23:59:00‘ and l.StartTime >=‘2017-12-05 00:00:00‘)
or (l.EndTime >=‘2017-12-05 00:00:00‘ and l.StartTime <=‘2017-12-05 00:00:00‘)
or (l.EndTime >=‘2017-12-12 23:59:00‘ and l.StartTime <=‘2017-12-12 23:59:00‘))
GROUP BY l.StartTime ,l.EndTime
ORDER BY l.StartTime ,l.EndTime asc, l.CreateTime desc;

技術分享圖片

自定義列標題 case when