sql : execute update when a certain condition is met

update config

set role = 'abc' 

where id = '2'  

     and (select 1 from (

             select 1 from config where role='abc' having count(1)<3

         ) t )

 

Update the role of id=2 in the config table to abc The precondition is that when the data in the table with the role of abc is less than 3

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326689508&siteId=291194637