对于一名员工,应在一行中返回上班时间和下班时间
For one employee, In time and Out time should be returned on one line
select
compcode, emplcode, attndate, costcode,
decode(shiftflg, 'I', readtime) INTIME,
decode(shiftflg, 'O', readtime) OUTTIME
from
ecatnrec
where
emplcode = 'RF025'
order by
emplcode;
您可以使用聚合:
select compcode, emplcode, attndate, costcode,
max(case when shiftflg = 'I' then readtime end) as INTIME,
max(case when shiftflg = 'O' then readtime end) as OUTTIME
from ecatnrec
where emplcode = 'RF025'
group by compcode, emplcode, attndate, costcode
order by emplcode;
这假设最多有 "I" 和一个 "O" 行用于 group by
键的唯一值。
select
compcode, emplcode, attndate, costcode,
decode(shiftflg, 'I', readtime) INTIME,
decode(shiftflg, 'O', readtime) OUTTIME
from
ecatnrec
where
emplcode = 'RF025'
order by
emplcode;
您可以使用聚合:
select compcode, emplcode, attndate, costcode,
max(case when shiftflg = 'I' then readtime end) as INTIME,
max(case when shiftflg = 'O' then readtime end) as OUTTIME
from ecatnrec
where emplcode = 'RF025'
group by compcode, emplcode, attndate, costcode
order by emplcode;
这假设最多有 "I" 和一个 "O" 行用于 group by
键的唯一值。