need the query for the o/p.

Database

need the query for the o/p.

hi

i have a table with data below and i want to display the result ass o/p below...thnks inadvance.

eid    ename     loc       flag

1      mahesh   ind       current

1      mahesh   usa      previous

o/p:

eid     ename   oldloc   newloc

1        mahesh  usa      ind

1 REPLY

Re: need the query for the o/p.

Hw about your previous to previous? you can try this way:

select eid,

ename,

max(case when flag='previous' then loc end) over(partition by eid,ename  order eid,ename ) oldloc,

max(case when flag='current' then loc end) over(partition by eid,ename  order eid,ename ) newloc from youttable

qualify row_number() over(partition by partition by eid,ename  order eid,ename)=1