sql - 我无法选择“案例”字段
问题描述
我无法选择一个字段并需要帮助。
WHEN dpav.isprimary = 1
THEN ct.accountnum
ELSE concat (ct.accountnum,'_',dpav.zipcode)
END 'Customeraccount'
在FROM子句之前,我想再次选择 case 子句(Customeraccount)
case
when DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '' then 'Yes'
when DeliveryAddresses <> '' or ct.INVOICEACCOUNT = ''
and Customeraccount LIKE '%[_]%' then 'No'
else 'No'
end 'KeyAccount'
我尝试使用引号('Customeraccount'),但它不起作用。
解决方案
您不能在定义它的同一个选择中使用列别名。
您仍然可以如下更新您的条件,它将为您提供所需的输出。
case
when (DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '') and dpav.isprimary = 1 then 'Yes'
when DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '' then 'No'
else 'No'
end 'KeyAccount'
即使省略第二个 where claus 也可以正常工作。
case
when (DeliveryAddresses <> '' or ct.INVOICEACCOUNT = '') and dpav.isprimary = 1 then 'Yes'
else 'No'
end 'KeyAccount'
推荐阅读
- python - 预期的 str 字节或 os.pathlike 对象不是 builtin_function_or_method
- java - 如何使用 TestNG 在 Selenium 的 IReporter 界面中使用 screeshotcapture?
- javascript - 无法访问 javascript 变量中的对象属性
- acumatica - 是否可以在 PXSelector 中输入新值
- css - 调整仪表元素的css而不破坏
- c++ - std::u8string 与 std::string 有何不同?
- python - 将 VGG 模型的图像大小从 64x64 调整为 224x224
- android - 溢出-x:滚动!重要不能在三星互联网上使用翻译的 SVG
- kubernetes - Openshift:oc登录失败
- python - 有没有办法在 Blender 中使用 python 脚本复制/粘贴动作关键帧?