我正在尝试在我的案例陈述中运行一个选择。
我无法链接所有表格,因为UDA_Checked表格多次都有我的公司自动键,所以我试图在案例中运行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条目的列表,并且每个值都在一行中,因此我没有重复的值。