我有一個 sql,它回傳如下資料:
SELECT DISTINCT
workitem_id,
case when state ='Created' then newimage_lastupdateddate else null end as creation_date,
case when state ='Disconnected' then newimage_lastupdateddate else null end as disconnect_date
from work_item
| workitem_id | 渠道 | 創立日期 | diconnect_date |
|---|---|---|---|
| 123 | 任務 | 2021-10-02 08:37:24 | 空值 |
| 123 | 任務 | 空值 | 2021-10-02 11:36:58 |
我想要 1 行中的資料,如下所示。
| workitem_id | 渠道 | 創立日期 | diconnect_date |
|---|---|---|---|
| 123 | 任務 | 2021-10-02 08:37:24 | 2021-10-02 11:36:58 |
我該怎么做 ?
uj5u.com熱心網友回復:
DISTINCT 正在產生問題。
嘗試
SELECT D
workitem_id,
min(case when state ='Created' then newimage_lastupdateddate else null end ) as creation_date,
max(case when state ='Disconnected' then newimage_lastupdateddate else null end) as disconnect_date
from work_item
group by workitem_id
不確定 min 和 max 是否最適合您的資料。如果您不確定,請在此處復制資料。
uj5u.com熱心網友回復:
嘗試聚合和分組 workitem_id
select workitem_id,
Max(case when state ='Created' then newimage_lastupdateddate end) as creation_date,
Max(case when state ='Disconnected' then newimage_lastupdateddate end) as disconnect_date
from work_item
group by workitem_id
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/325094.html
標籤:sql
上一篇:根據gitdescribe的輸出重新構建make目標
下一篇:如何使用SQL將這四行轉換為列
