2

I have two following update statements:

update tb1
set col1=1
where id in ('1', '2', '3')

update tb1
set col1=0
where id not in ('1', '2', '3')

Can I combine above two update statements into one?

4

2 回答 2

6

尝试这个:

UPDATE tb1 SET col1= CASE WHEN id in ('1', '2', '3') THEN 1 ELSE 0 END
于 2012-09-10T16:00:28.123 回答
2
UPDATE tb1 
SET col1 = CASE WHEN id in (1, 2, 3) 
                    THEN 1 
                WHEN id NOT IN (1, 2, 3)
                    THEN 0
                ELSE
                    col1
           END ;
于 2012-09-10T17:58:20.957 回答