用sql 语句两字段比较返回一个值

2025年03月01日 10:37
有3个网友回答
网友(1):

update b set x = case when a.qty >= b.qty1 then 'yes' else 'no' end
from a , b
where (这里加入a和b表对应记录的条件,如a.id = b.id,否则没有条件更新错误。)

网友(2):

这首先要求a与b 两表有个唯一关联的字段才能实现,假定为字段名:ID
select b.* ,
case when a.qry > b.qty1 then 'YES' else 'NO' end as x
from b , a
where b.id = a.id

网友(3):

a b表是啥关系,有关联字段没有?还是说每个表只有一行值?