首页 > 解决方案 > 如何在 Oracle 中转置?

问题描述

我有一张桌子: 前

我想在 Oracle SQL 中做到这一点: 后

如何在 SQL 中编写代码?

标签: sqloraclepivot

解决方案


您可以按如下方式使用条件聚合:

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

推荐阅读