Skip to content
Advertisement

SQL show based on date condition

I have following query to start of with:

I then get following table (only a snapshot for better desciption):

I now have a problem:

  • I only want to show the services where the service starting with ‘AAF21 OKN’ is first (by date).
  • Patient ID: ‘Forløb10030’ is for example what i want.
  • But in Patient ID: ‘Forløb08196’, I don’t want the Service ‘UXMG25’ row to be showed. As it has happened before the service ‘AAF21 OKN’

Advertisement

Answer

If I understand what you’re after, I think the following will meet your needs:

The Part 1 gets you all the “AAF21 OKN” records. Part 2 gets you all the other records, but only where there EXISTS an “AAF21 OKN” record for the same patient which is on the same date or earlier (you may want to change the <= to < depending on your expectations).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement