我想將步驟表的行作為新表的列
步數表
ID |Steps | Steps_Date
1 | Create | 5/9/2020
1 |Schedule | 5/11/2020
1| Complete | 5/12/2020
1| Request | 5/10/2020
2| Request | 5/12/2021
這些是轉換為列的步驟表的行。
新表
ID | Create | Request | Schedule | Complete
1 | 5/9/2020|5/10/2020|5/11/2020|5/12/2020
2 | Null | 5/12/2021 | Null | Null
uj5u.com熱心網友回復:
做一個GROUP BY。使用case 運算式進行條件聚合:
select id,
max(case when Steps = 'Create' then Steps_Date end) as create_date,
max(case when Steps = 'Request' then Steps_Date end) as Request_date,
max(case when Steps = 'Schedule' then Steps_Date end) as Schedule_date,
max(case when Steps = 'Complete' then Steps_Date end) as Complete_date
from Steps_table
group by id
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/325095.html
上一篇:將sql中的資料格式化為單行
