SQL的判断语句:case when语句以及与update set的使用

参考链接:

https://blog.csdn.net/dyh36_c/article/details/100066457?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

 

1、

update TD_XXX
set
djyzmdm=null,
djyzmsj=null,
DLCS= case when DLCS is null then 1 else DLCS+1 end
where djsj='xxx'

2、
update `TD_XXX`
set
`datetime` = 1434567890,
`status` = case `id` when 12 Then 1 when 13 Then 2 when 14 Then 1 end
where `id` in (12,13,14)
 

UPDATE  test.wjztest set str=
    CASE 
    WHEN  '${NUM_DIFF}'<>'0' AND '${TIME_DIFF}'='24' THEN 'Number Error: ${TABLENAME} Time Diff: ${TIME_DIFF}  Num Diff: ${NUM_DIFF}'
    WHEN  '${NUM_DIFF}'<>'0' AND '${TIME_DIFF}'<>'24' THEN 'Time and Number Error: ${TABLENAME} Time Diff: ${TIME_DIFF}  Num Diff: ${NUM_DIFF}'    
    WHEN  '${NUM_DIFF}'='0' AND '${TIME_DIFF}'<>'24' THEN 'Time Error: ${TABLENAME} Time Diff: ${TIME_DIFF}  Num Diff: ${NUM_DIFF}'    
    ELSE  'OK'
    END 
WHERE tablename='${TABLENAME}'

 

你可能感兴趣的:(SQL,大数据)