我无法选择"case"字段



我无法选择一个字段,需要帮助。

WHEN dpav.isprimary = 1
THEN ct.accountnum
ELSE concat (ct.accountnum,'_',dpav.zipcode) 
END 'Customeraccount'

FROM子句之前,我想再次选择案例子句(客户帐户(

case 
when DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '' then 'Yes' 
when DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '' 
and Customeraccount LIKE '%[_]%' then 'No'
else 'No' 
end 'KeyAccount'

我尝试使用引号("客户帐户"(,但它不起作用。

不能在定义列别名的同一选择中使用列别名。

您仍然可以按如下方式更新条件,它将为您提供所需的输出。

case 
when (DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '') and dpav.isprimary = 1 then 'Yes'
when DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '' then 'No'
else 'No' 
end 'KeyAccount'

即使省略克劳斯的第二个也可以正常工作。

case 
when (DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '') and dpav.isprimary = 1 then 'Yes'
else 'No' 
end 'KeyAccount'

最新更新