What is the problem with mysql nesting case when?

The

sql statement is as follows:

SELECT
    a.uc_id id,
    (
        CASE WHEN a.uc_realname IS NULL OR a.uc_realname =""
        THEN a.uc_sys_name ELSE a.uc_realname END
    ) AS realName,
    a.uc_register_time registerTime,
    a.uc_phone phone,
    a.uc_last_login_time lastLoginTime,
    (
        CASE
        WHEN LEFT (a.uc_code, 2) = "00" THEN
            ""
        ELSE
            ""
        END
    ) type,
    (
        CASE
        WHEN a.uc_flag = 0 THEN
            ""
        WHEN a.uc_flag = 1 THEN
            ""
        WHEN a.uc_flag = 2 THEN
            ""
        END
    ) flagName,
    b.post_status,
    (
        CASE 
        WHEN b.post_status IS NULL OR b.post_status = "" 
        THEN 
        (
            CASE
            WHEN tmp.ctime IS NOT NULL AND tmp.ctime <> ""
            THEN ""
            ELSE "" END
        ) 
        ELSE
        (
            CASE 
            WHEN b.post_status = 0 
            THEN ""
            WHEN b.post_status = 1 
            THEN ""
            WHEN b.post_status = 2 
            THEN ""
            WHEN b.post_status = 3 
            THEN ""
            ELSE "" END
        )
        END
    ) `status`,
    tmp.ctime,
    b.memo,
    c.realname manageRealName,
    c.id manageUseId
FROM
    bco_uc.uc_app_user a
LEFT JOIN bco_web.web_crm_dz b ON a.uc_id = b.app_user_id
LEFT JOIN bco_web.web_manage_user c ON b.manage_user_id=c.id
LEFT JOIN (
    SELECT
        t.uc_id,
        MAX(t1.create_time) ctime
    FROM
        bco_uc.uc_app_user t
    LEFT JOIN bco_jobpost.job_position_apply t1 ON t.uc_id = t1.user_id COLLATE utf8mb4_unicode_ci
    WHERE t1.status="draft" GROUP BY t.uc_id
) tmp ON a.uc_id = tmp.uc_id

query results are as follows:

imagepng

did you find that the outermost judgment of case when did not take effect, and why?

Mar.21,2021

because in Mysql, when the integer 0 is compared with the empty string'', the result is true, you need to put

b.post_status = ''
Change

to

CAST(b.post_status AS CHAR) = ''

you can take a look at the document Comparison Functions and Operators .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c7a7-2c323.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c7a7-2c323.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?