select
compcode, emplcode, attndate, costcode,
decode(shiftflg, 'I', readtime) INTIME,
decode(shiftflg, 'O', readtime) OUTTIME
from
ecatnrec
where
emplcode = 'RF025'
order by
emplcode;
Asked
Active
Viewed 27 times
-1

marc_s
- 732,580
- 175
- 1,330
- 1,459

Prabha Christ
- 131
- 2
- 2
- 10
-
1Use `GROUP BY` AND `MAX`? – Richard Hansell Jul 03 '18 at 10:46
1 Answers
1
You can use aggregation:
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;
This assumes that there is at most on "I" and one "O" row for unique values of the group by
keys.

Gordon Linoff
- 1,242,037
- 58
- 646
- 786