mysql有A(id,sex,par,c1,c2),B(id,age,c1,c2)两张表,其中A.id与B.id关联

mysql有A(id,sex,par,c1,c2),B(id,age,c1,c2)两张表,其中A.id与B.id关联
12. 有A(id,sex,par,c1,c2),B(id,age,c1,c2)两张表,其中A.id与B.id关联,现在要求写一条SQL语句,将B中age>50的记录的c1、c2更新到A表中统一记录中的c1、c2字段中
琥珀dico 1年前 已收到1个回答 举报

里龙 幼苗

共回答了24个问题采纳率:87.5% 举报

update A
set (c1,c2) =(select B.c1,B.c2 from B where A.id=B.id and B.age>50)
where exists(select 1 from B where A.id=B.id and B.age>50)
如果在set那报错你可以试试
update A
set (c1,c2) =((select B.c1,B.c2 from B where A.id=B.id and B.age>50))
where exists(select 1 from B where A.id=B.id and B.age>50)

1年前

5
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.136 s. - webmaster@yulucn.com