CASE声明条件postgres

时间:2017-08-10 13:06:16

标签: postgresql

我正在尝试为员工创建一个以代码10开头的报告....并为他们应用特定的工作代码。他们在表格中有一个糟糕的工作代码。我在哪里以及在哪里检查案件中的情况 声明?

Example condition :
    Apply job_code 'AC' for the employees that start with the code 10.

表1:customer_test

employee_code

Job_code_id

company_code

join_year

表2:Company_store

Job_code_id

JOB_CODE

Company_code

Join_year

SELECT 

ct.employee_code,ct.job_code_id old,ct.company_code ,cs.job_Code_id new ,cs.job_code new code,

CASE

    WHEN (ct.employee_code LIKE '10%') THEN CAST(cs.job_Code_id AS varchar) //I need to apply the condition here? apply the specific job code id based on the conditions.

ELSE CAST(cs.job_Code_id AS varchar)

END AS REPORT

FROM customer_test ct,company_store cs

WHERE ct.company_code=cs.company_code

and ct.job_code_id =cs.job_code_id

and ct.join_year=cs.join_year;

Thanks in advance.

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方式:

case
when employee_code like '10%' then
    (
    select  job_code
    from    customer_test
    where   employee_code ='AC'
    )
else cast(job_Code as varchar(50))
end