Postgresql的CASE语法嵌套

SELECT
    a.city,
    a.staff_name,
    (
CASE
    
    WHEN a.basic_pay > b.top_pensions_insurance THEN
    b.top_pensions_insurance * b.company_pensions_insurance_pay 
    WHEN a.basic_pay < b.top_pensions_insurance THEN CASE WHEN a.basic_pay > a.current_pensions THEN
    a.basic_pay * b.company_pensions_insurance_pay 
WHEN a.basic_pay < a.current_pensions THEN
a.current_pensions * b.company_pensions_insurance_pay 
END 
END 
) AS company_pensions 
FROM
    social_security_detail a
LEFT JOIN social_security_contrib_ratio b ON a.city = b.city;

你可能感兴趣的:(Postgresql的CASE语法嵌套)