sql语句多字段按照不同条件更新

UPDATE test_plan p 
SET p.test_start_time =
CASE
        WHEN p.test_start_time IS NULL THEN
        '2019-09-09 09:09:09' else p.test_start_time 
    END,
    p.test_end_time = '2020-12-12 12:12:12'
WHERE
    (select ps.plan_id from test_plan_scene ps where ps.id =
        (select a.test_plan_scene from test_active a where a.id= #{id}))

test_start_time字段满足为空且主键符合时更新,test_end_time字段满足主键符合时更新,如果还需要其他条件继续when then

你可能感兴趣的:(sql语句多字段按照不同条件更新)