0

I have a table: Before

And I want to make it like this in Oracle SQL: After

How can I write code in SQL?

MT0
  • 143,790
  • 11
  • 59
  • 117
agong
  • 55
  • 1
  • 1
  • 6

1 Answers1

2

You can use the conditional aggregation as follows:

select subjid,
       max(case when status = 'most recent dose' then date end) as most_recent_dose
       max(case when status = 'second most recent dose' then date end) as second_most_recent_dose
       max(case when status = 'dosing' then date end) as dosing
  from your_table
group by subjid
Popeye
  • 35,427
  • 4
  • 10
  • 31