日期:2014-05-17 浏览次数:20866 次
select *
from tableA f
where f.TYPE = '入职日'
and exists
(select 1
from tableA f2
where f2.NAME = f.NAME
and f2.TYPE = '离职日'
and f2.DATE < f.DATE);
with A_CODE as
(
select 'JACK' namea,'生日' TYPEa,'1980' DATEa from dual union all
select 'JACK' namea,'入职日' TYPEa,'2000' DATEa from dual union all
select 'JACK' namea,'离职日' TYPEa,'2008' DATEa from dual union all
select 'TOM' namea,'生日' TYPEa,'1982' DATEa from dual union all
select 'TOM' namea,'入职日' TYPEa,'2013' DATEa from dual union all
select 'TOM' namea,'离职日' TYPEa,'2009' DATEa from dual union all
select 'SAM' namea,'生日' TYPEa,'1988' DATEa from dual union all
select 'SAM' namea,'入职日' TYPEa,'2006' DATEa from dual
)
select *
from (select tt.namea,
max(decode(TYPEa, '生日', DATEa, null)) as 生日,