Sql 在案例中选择

Sql 在案例中选择,sql,oracle,case,Sql,Oracle,Case,我正在尝试在案例语句中运行select 我无法链接所有的表,因为UDA_Checked表多次使用my company自动键,因此我尝试在本例中运行select,但在“from”处出现错误“missing expression” 谢谢, SELECT CASE WHEN (SELECT attr.uda_auto_key FROM USER_DEFINED_ATTRIBUTES attr JOIN U

我正在尝试在案例语句中运行select

我无法链接所有的表,因为UDA_Checked表多次使用my company自动键,因此我尝试在本例中运行select,但在“from”处出现错误“missing expression”

谢谢,

SELECT
    CASE
        WHEN
            (SELECT attr.uda_auto_key
            FROM USER_DEFINED_ATTRIBUTES attr 
            JOIN UDA_CHECKED uda ON uda.UDA_AUTO_KEY = UDA_AUTO_KEY
            WHERE uda.AUTO_KEY = cmp.CMP_AUTO_KEY)
            AND
            attr.UDA_AUTO_KEY = 40)
                THEN
                    'Parts Sales'
    END AS "Parts Sales",
    rdx.RDX_AUTO_KEY, rdx.RDX_CONTACT_NAME, rdx.TITLE, rdx.PHONE_NUMBER, rdx.MOBILE_PHONE, rdx.EMAIL_ADDRESS, 
    cmp.COMPANY_NAME, cmp.COMPANY_CODE, cmp.ATTENTION, cmp.ADDRESS1, cmp.ADDRESS2, cmp.ADDRESS3, cmp.CITY, cmp.COUNTRY, cmp.STATE, cmp.ZIP_CODE, cmp.PHONE_NUMBER, cmp.EMAIL_ADDRESS, cmp.NOTES, cmp.VENDOR_FLAG, cmp.CUSTOMER_FLAG
FROM ROLODEX rdx
LEFT JOIN COMPANY_ROLODEX cprol ON cprol.RDX_AUTO_KEY = rdx.RDX_AUTO_KEY
LEFT JOIN COMPANIES cmp ON cprol.CMP_AUTO_KEY = cmp.CMP_AUTO_KEY
LEFT JOIN AIRCRAFT act ON act.CMP_OWNER = cmp.CMP_AUTO_KEY
LEFT JOIN MODEL mdl ON mdl.MDL_AUTO_KEY = act.MDL_AUTO_KEY
WHERE 
rdx.HISTORICAL = 'F'
好的,我被建议更详细一点,所以我将粘贴我的声明的更简单版本:

SELECT
    CASE
        WHEN
            attr.UDA_AUTO_KEY = 1 -- UDA_AUTO_KEY 1 is the 'Company Value 1' value in the user_defined_attributes table that is connected to the rolodex table by the company_rolodex and companies tables
                THEN
                    'Company Value 1'
    END AS "Company Value 1",
    CASE
        WHEN
            attr.UDA_AUTO_KEY = 2
                THEN
                    'Company Value 2'
    END AS "Company Value 2",
        CASE
        WHEN
            attr.UDA_AUTO_KEY = 3
                THEN
                    'Company Value 3'
    END AS "Company Value 3",
    rdx.RDX_AUTO_KEY, rdx.RDX_CONTACT_NAME,cmp.COMPANY_NAME -- other output values. So I want to know the person's name, their company and if they have Company Value 1, 2 or 3 checked, or all three.
FROM ROLODEX rdx  -- This is where the customer's name and email address are stored.
LEFT JOIN COMPANY_ROLODEX cprol ON cprol.RDX_AUTO_KEY = rdx.RDX_AUTO_KEY  -- This connects the customers to the accounts on the 'companies' table
LEFT JOIN COMPANIES cmp ON cprol.CMP_AUTO_KEY = cmp.CMP_AUTO_KEY  -- This table will connect the customers on the rolodex table and the company name on the compaines table via the company rolodex table.
JOIN UDA_CHECKED uda ON uda.AUTO_KEY = cmp.CMP_AUTO_KEY -- This is where things mess up. Because there can be many check boxes on one company the company auto key apears many times on this table as the 'auto_key' value.
LEFT JOIN USER_DEFINED_ATTRIBUTES attr ON uda.UDA_AUTO_KEY = attr.UDA_AUTO_KEY -- This is to help define the 'company value' check boxes.
WHERE
rdx.EMAIL_ADDRESS = 'TEST@aol.com' -- I am using this where to disply that there are two line outputs and not one.
以下是输出的副本:

Company Value 1                          8117   Tim Cartney Air, Inc.
                 Company Value 2         8117   Tim Cartney Air, Inc.
我希望这是一行:

Company Value 1     Company Value 2      8117   Tim Cartney Air, Inc.
我想获得数据库中每个rolodex条目的列表,以及在一行中与它们对应的每个值,这样我就不会有重复的值。

终止案例陈述 您需要以attr.UDA\u AUTO\u键为轴心


例如

这不起作用-您不能像这样在
案例中选择
,因为您需要在那里提供表达式。同样,转述你的问题通常是不好的做法,会使人们更不愿意给你帮助,这可能是重复的谢谢你,维德曼塔斯。我认为这种不同的方法可能是最好的解决方案,因为主语句中不会包含重复项。为了示例的目的,将您的查询减少到最小,提供示例数据和预期结果(以及您尝试执行的意图),您将很快得到帮助。使用
MAX(CASE…)
以消除空值。我认为您可能还必须在其他列上使用
MAX
,或者使用分组方式,但不能确定,因为没有数据可以测试它。