我先得到最新的一条数据(标的id是自增的)于是我用
update class set name ='sads' where id in (select max(id) from class)结果报错 不知道如何去解决这个问题

解决方案 »

  1.   

    试试这个
    update class a set a.name ='sads' where a.id in (select max(b.id) from class b)
    原因可能是update class这个表的时候mysql锁定这张表,为什么要锁定的原因类似于where条件中不能用聚集函数,因为执行sql时不能确定聚集函数的值,类比你的子查询结果对sql来说不能确定,所以报错
      

  2.   

    如果你是做Web开发建议分别做个独立的函数,
    int fun1()
    select max(id) from A
    return rs.getInt(1);
    fun2()
    int maxid = fun1();
    select * from A where id = maxid;
    这样做清晰!