日期:2014-05-17 浏览次数:21054 次
with ax as(
select stu.name name,
att.checktime checktime,
att.type type
from student stu,
attendance att
where
att.stu_obid=stu.id
group by stu.name,att.checktime,att.type
)
select name,min(checktime),0 from ax where type='进校'
union
select name,0,max(checktime) from ax where type='离校'
with attendance as
(
select 1 id,11 stu_obid,'2013-9-1 08:12:13' checktime,'进校' type from dual union all
select 2 id,11 stu_obid,'2013-9-1 12:30:13' checktime,'离校' type from dual union all
select 3 id,11 stu_obid,'2013-9-1 14:30:13' checktime,'进校' type from dual union all
select 4 id,11 stu_obid,'2013-9-1 15:30:31' checktime,'离校' type from dual l
)
select stu_obid,
min(decode(type,'进校',checktime)) m_time,
max(decode(type,'离校',checktime)) n_time
from attendance
group by stu_obid
stu_obid m_time n_time
---------------------------
1 11 2013-9-1 08:12:13 2013-9-1 15:30:31