我撰寫了這組代碼,它以典型的 SQL 格式作業,但是當我嘗試通過雪花資料庫運行它時,由于語法而出錯。重新排列此陳述句以正確適用于雪花的最佳方法是什么。感謝您的時間!
if [CUST_TYP] = "Auction" THEN "Auction"
elseif [CUST_TYP] = "Broker / Reseller" THEN "Wholesale"
elseif [CUST_TYP] = "Cat Dealer" THEN "Wholesale"
elseif [CUST_TYP] = "Cat Dealer Rental Fleet" THEN "Wholesale"
elseif [CUST_TYP] = "Cat Private Auction" THEN "Auction"
elseif [CUST_TYP] = "Customer In-territory" THEN "Retail"
elseif [CUST_TYP] = "Customer out of territory, in country" THEN "Retail"
elseif [CUST_TYP] = "Customer out of territory, out of country" THEN "Retail"
else [CUST_TYP]
endif
uj5u.com熱心網友回復:
您可以像這樣使用 CASE:
case CUST_TYP
when 'Auction' THEN 'Auction'
when 'Broker / Reseller' THEN 'Wholesale'
when 'Cat Dealer' THEN 'Wholesale'
when 'Cat Dealer Rental Fleet' THEN 'Wholesale'
when 'Cat Private Auction' THEN 'Auction'
when 'Customer In-territory' THEN 'Retail'
when 'Customer out of territory, in country' THEN 'Retail'
when 'Customer out of territory, out of country' THEN 'Retail'
end
另請注意,雪花雙引號不是有效的字串,僅對識別符號(表/列名稱)有效。
當這樣使用時:
select
'Auction' as cust_typ,
case CUST_TYP
when 'Auction' THEN 'Auction'
when 'Broker / Reseller' THEN 'Wholesale'
when 'Cat Dealer' THEN 'Wholesale'
when 'Cat Dealer Rental Fleet' THEN 'Wholesale'
when 'Cat Private Auction' THEN 'Auction'
when 'Customer In-territory' THEN 'Retail'
when 'Customer out of territory, in country' THEN 'Retail'
when 'Customer out of territory, out of country' THEN 'Retail'
end as chained_if
;
給出:
CUST_TYP | CHAINED_IF |
---|---|
拍賣 | 拍賣 |
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/496726.html
上一篇:我嘗試了這個簡單的javascript代碼ifelseblockError:-Declarationorstatementexpected