select
complaint_id
,complaint_type
,COMMUNICATION_ID
,max(case when delivery_type='deliver_once' then '1' else '0' end as IS_ADDON_REFUND)
from
complaints_order_status
group by 1,2,3
它有什么問題?
uj5u.com熱心網友回復:
您不能在 MAX 函式中命名列。也使用整數表示 1 和 0。此外,如果您可以粘貼錯誤訊息,您會得到它會有所幫助。但是嘗試:
select complaint_id ,
complaint_type ,
COMMUNICATION_ID ,
max(case when delivery_type='deliver_once' then 1 else 0 end) as IS_ADDON_REFUND
from complaints_order_status
group by complaint_id ,complaint_type ,COMMUNICATION_ID
uj5u.com熱心網友回復:
我從您的代碼中更改了兩件事:
- 使用分組依據中的別名。1,2,3 不適用于所有平臺。
- 在 max 子句括號外給出別名。如果這不是您的最終輸出,則無需為 case when子句命名。
這是最終代碼:
select complaint_id ,complaint_type ,COMMUNICATION_ID ,
max(case when delivery_type='deliver_once'
then '1' else '0'
end )as IS_ADDON_REFUND
from complaints_order_status
group by complaint_id,
complaint_type,
COMMUNICATION_ID
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/422490.html
標籤:
上一篇:使用計數和按欄位排序優化子查詢
