我需要从Case语句中的SQL Select语句中获取Supplier ID。一旦我将A.SUPPLIER_ID
放入Select语句,我就会收到错误。这该怎么做?
Select
CASE
WHEN TYPE = 1 THEN
(
SELECT A.name
from BIZZXE_V2_SCH.SUPPLIERS A
where A.SUPPLIER_ID = 30
)
ELSE
(
SELECT A.name
from BIZZXE_V2_SCH.STOCK_SUPPLIER A
where A.SUPPLIER_ID = 31
)
END name
from DUAL;
答案 0 :(得分:1)
您无法将完整查询放入case
语句中。但这应该有用
SELECT name
from BIZZXE_V2_SCH.SUPPLIERS
where SUPPLIER_ID = 30 and TYPE = 1
union all
SELECT name
from BIZZXE_V2_SCH.STOCK_SUPPLIER
where SUPPLIER_ID = 31 and TYPE <> 1
答案 1 :(得分:0)
你应该能够在WHERE语句中处理这个问题,就像这样。
SELECT A.name
FROM BIZZXE_V2_SCH.STOCK_SUPPLIER A
WHERE (A.SUPPLIER_ID = 30 AND TYPE = 1) OR
A.SUPPLIER_ID = 31
答案 2 :(得分:0)
使用ghi
声明
IF/ELSE