试试这个 update class a set a.name ='sads' where a.id in (select max(b.id) from class b) 原因可能是update class这个表的时候mysql锁定这张表,为什么要锁定的原因类似于where条件中不能用聚集函数,因为执行sql时不能确定聚集函数的值,类比你的子查询结果对sql来说不能确定,所以报错
如果你是做Web开发建议分别做个独立的函数, int fun1() select max(id) from A return rs.getInt(1); fun2() int maxid = fun1(); select * from A where id = maxid; 这样做清晰!
update class a set a.name ='sads' where a.id in (select max(b.id) from class b)
原因可能是update class这个表的时候mysql锁定这张表,为什么要锁定的原因类似于where条件中不能用聚集函数,因为执行sql时不能确定聚集函数的值,类比你的子查询结果对sql来说不能确定,所以报错
int fun1()
select max(id) from A
return rs.getInt(1);
fun2()
int maxid = fun1();
select * from A where id = maxid;
这样做清晰!