2017-02-21 58 views
0

我在努力構建一個正在運行的SQL查詢來提取我需要的信息。我是SQL(Oracle)的新手,不確定這是否可能。Oracle SQL如何在多個變量上篩選列

下面是生成的代碼開始查詢,這是正確的:

SELECT 
    0 s_0, 
    "Workforce Management - Work Relationship Real Time"."Legal Employer"."Name" s_1, 
    "Workforce Management - Work Relationship Real Time"."Worker Payroll"."Worker Payroll Name" s_2, 
    "Workforce Management - Work Relationship Real Time"."Worker"."Employee First Name" s_3, 
    "Workforce Management - Work Relationship Real Time"."Worker"."Employee Last Name" s_4, 
    "Workforce Management - Work Relationship Real Time"."Worker"."Person Number" s_5 
FROM "Workforce Management - Work Relationship Real Time" 

然後,我構建了一個過濾器,以確定薪資組的員工,其沒有與正確的法律僱主匹配:

WHERE 
(("Worker Payroll"."Worker Payroll Name" = 'Paygroup1') AND ("Legal Employer"."Name" <> 'Paygroup1 Legal Employer')) 

這讓我想起誰都有錯相應的法律僱主關於他們的薪酬組(即員工在Paygroup1應該有相應的法律Paygroup1僱主的僱員那麼這將返回類似:

員工編號 - 員工姓名 - Paygroup1 - Paygroup2法律僱主

然而,當我添加了另一個篩選到它,我得到的錯誤。例如:

WHERE 
((("Worker Payroll"."Worker Payroll Name" = 'Paygroup1') AND ("Legal Employer"."Name" <> 'Paygroup1 Legal Employer'))) 
AND 
(("Worker Payroll"."Worker Payroll Name" = 'Paygroup2') AND ("Legal Employer"."Name" <> 'Paygroup2 Legal Employer')) 

總共有8個。這在SQL中可能嗎?如果是這樣,我做錯了什麼?我用他們的過濾器構建了8個單獨的報告,他們都工作,但最好我想要所有8個過濾器報告。

+0

定義 「我得到的錯誤」。你有錯誤信息嗎?結果是否錯誤?例如。如果您想要獲得所有員工的薪酬組1合法僱主或其薪酬組2合法僱主錯誤的所有員工,則需要用'OR'替換您的'AND'。 'AND'將只返回合法僱主都有錯的僱員。 –

+0

@FrankSchmitt嗨,弗蘭克,謝謝你。通過放入或者而不是和過濾器運行沒有錯誤,我感謝幫助! –

回答

0

使用OR

WHERE ( "Worker Payroll"."Worker Payroll Name" = 'Paygroup1' 
     AND "Legal Employer"."Name"    <> 'Paygroup1 Legal Employer' 
    ) 
OR ( "Worker Payroll"."Worker Payroll Name" = 'Paygroup2' 
     AND "Legal Employer"."Name"    <> 'Paygroup2 Legal Employer' 
    )