一个sql语句 怎么实现 根据另一张表的数据有无 来更改表里的一个字段 比如关联的那张表有数据这个字段就修改成1,如果关联的那张表没数据,就把这个字段修改成0~(这两张表有关联关系 )
update a set xx= case when b.xx is null then 1 else 0 end from table1 a left join table2 b on a.xx=b.xx
自己套
select b.字段1, b.字段2, case when a.字段2 is null then '0' else '1' end left join b on a.字段1 = b.字段1
用case when