I have a table (op) with the following fields:
id, attdate, refdate and attend. If I want to see many occurences of id records, I can use the following:
Now if I want to see the details of just one record, I can use id and order by attdate, e.g,
which gives the following results:
Now here is the challenge. I want to replace all second refdate (which in this case is 2003-12-30) with the first attdate (in this case 2004-04-01), the third refdate with the second attdate, etc. This process carries on until it reaches a point where attend is 5 or 6, then it stops. I don't want id to be unique because I will lose some important records. All I am interested in is replace all refdate starting from the 2nd one as explained, where every count of id > 1 and attend is not 5 or 6.
How do I write the code to achieve this? Could someone help me, please.
Thank you in advance for your help.
jcad1
id, attdate, refdate and attend. If I want to see many occurences of id records, I can use the following:
Code:
select id, count(*)
from op
group by id
having count(*)>1
Now if I want to see the details of just one record, I can use id and order by attdate, e.g,
Code:
select *
from ac_op_refs
where id = 'RWEAAR42625730/12/2003'
order by attdate
which gives the following results:
Code:
[b]id attdate refdate attend [/b]
RWEAAR42625730/12/2003 2004-04-01 2003-12-30 2
RWEAAR42625730/12/2003 2004-05-27 2003-12-30 2 RWEAAR42625730/12/2003 2004-06-17 2003-12-30 3
RWEAAR42625730/12/2003 2004-07-10 2003-12-30 5
Now here is the challenge. I want to replace all second refdate (which in this case is 2003-12-30) with the first attdate (in this case 2004-04-01), the third refdate with the second attdate, etc. This process carries on until it reaches a point where attend is 5 or 6, then it stops. I don't want id to be unique because I will lose some important records. All I am interested in is replace all refdate starting from the 2nd one as explained, where every count of id > 1 and attend is not 5 or 6.
How do I write the code to achieve this? Could someone help me, please.
Thank you in advance for your help.
jcad1