日期:2014-05-16  浏览次数:20680 次

请教一个mysql update数据表更新语句, 高手 help
有两个表,
表a: (aid, a_active)

表b: (bid, aid, b_active)

active 取值 0, 1 (true, false)。 

表a中 a_active的值取决于 表b中 b_active的值, 当 a.aid=b.aid, b.b_active全为0 时, a的a_active 为 0 , 否则为 1

想要更新 表a中的a_active的值, sql语句如何实现这个更新???

不知道我的描述大家能不能看明白,希望能得到高手的指点。谢谢!

------解决方案--------------------
update a 
set a_active=(select case when b.b_active=0 then a.a_active=0 else 1 end from a,b where a.aid=b.aid)
where a.aid=b.aid and b.b_active=0
------解决方案--------------------
update a
set a_active=(select max(b_active) from b where aid=a.aid)