Frage

ID....| Date Created on System |.Action..............| Appointment Date
-----------------------------------------------------------------------------
ID123 |......15/03/2013 16:32..| Due.......          |.NULL
ID123 |......05/04/2013 09:27..|.Appointment booked..|.08/04/2013 11:30
ID123 |......24/03/2014 11:55..|.Appointment booked..|.10/04/2014 09:30
ID123 |......09/02/2014 11:43..|.Appointment Due.....|.NULL
ID123 |......24/03/2014 11:55..|.Appointment booked..|.20/06/2014 09:30

I need to separate the above result-set every time 'appointment Due' appears with the succeeding Appointments booked actions linked however I also need to filter the Appointments Booked by the created date giving me the Appointment Due date and the earliest Appointment Booked date with in the group

i.e

ID....| Date Created on System |.Action............| Appointment Date
-----------------------------------------------------------------------------
ID123 |.15/03/2013 16:32.......|.Appointment Due...|...NULL


ID123 |.05/04/2013 09:27.......|.Appointment booked.|.08/04/2013 11:30

The final resulting set should be two rows as follows

ID    | Date Created on System 1 | Action 1        | Date Created on System | Action 2          | Appointment Date|
---------------------------------------------------------------------------------------------------------------------
ID123 | 15/03/2013 16:32         | Appointment Due | 05/04/2013 09:27       | Appointment booked | 08/04/2013 11:30
ID123 | 09/02/2014 11:43         | Appointment Due | 24/03/2014 11:55       | Appointment booked | 20/06/2014 09:30

Thanks in advance!

War es hilfreich?

Lösung

I have created a sqlFiddle for you demonstrating this. I have added an ID column and PersonId column as per your comments: see here

Hope this works for you!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top