duplicate resluts

谁都会走 提交于 2019-12-25 02:31:49

问题


God day! I am running an extract of our Rolodex and including some user-defined fields, as you can below:

The problem I have is that I am getting duplicate results when a Rolodex entry qualifies for more than one case. So if a company is a 'Bell Owner or Operator' and a 'Fixed Wing' the result includes one entry for each, duplicating the email address.

Thank you for the help, this must be basic for y'all.

SELECT
    CASE
        WHEN
            attr.UDA_AUTO_KEY = 24
                THEN
                    'Bell Owner or Operator'
    END AS "Bell Owner or Operator",
        CASE
        WHEN
            attr.UDA_AUTO_KEY = 26
                THEN
                    'Fixed Wing'
    END AS "Fixed Wing",
    CASE
        WHEN
            attr.UDA_AUTO_KEY = 25
                THEN
                    'Rotorcraft'
    END AS "Rotorcraft",
    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,
    act.TAIL_NUMBER, act.SERIAL, mdl.MODEL_NUMBER, mdl.DESCRIPTION
FROM ROLODEX rdx
JOIN COMPANY_ROLODEX cprol ON cprol.RDX_AUTO_KEY = rdx.RDX_AUTO_KEY
JOIN COMPANIES cmp ON cprol.CMP_AUTO_KEY = cmp.CMP_AUTO_KEY
LEFT JOIN UDA_CHECKED uda ON uda.AUTO_KEY = cmp.CMP_AUTO_KEY
LEFT JOIN USER_DEFINED_ATTRIBUTES attr ON uda.UDA_AUTO_KEY = attr.UDA_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 attr.AUTO_KEY_PREFIX = 'CMP'
AND
rdx.HISTORICAL = 'F'

回答1:


If you are getting duplicated rows, then one of your joins are finding multiple matches. Additionally, your case statement looks incorrect (possibly). Normally should be one instead of three.

CASE
    WHEN
        attr.UDA_AUTO_KEY = 24
            THEN
                'Bell Owner or Operator'
    WHEN
        attr.UDA_AUTO_KEY = 26
            THEN
                'Fixed Wing'
    WHEN
        attr.UDA_AUTO_KEY = 25
            THEN
                'Rotorcraft'
END AS [ColumnNameForThis],


来源:https://stackoverflow.com/questions/48674228/duplicate-resluts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!