表experience中有字段 id,resume_id,totime,lastjob 
将resume_id相同的字段中,totime最大的lastjob的值改为1。所有字段都是数字型的。
谢谢!

解决方案 »

  1.   

    mysql> update experience a,(select resume_id,max(totime) totime from experience group by resume_id) t set a.lastjob =1 where a.resume_id=t.resume_id and a.totime=t.totime;
      

  2.   

    谢谢vipper23,刚才忘记说明一点,totime的值有很多重复的,只想得到所有resume_id相同的字段中,只有一条记录的lastjob为1
      

  3.   

    mysql> update experience a,(select max(id) id,resume_id,max(totime) totime from experience group by resume_id) t
     set a.lastjob =1 where a.resume_id=t.resume_id and a.totime=t.totime and a.id=t.id;
      

  4.   

    create view experience_view as 
    select t.id from (select id,resume_id,totime from experience order by resume_id,totime desc) as t group by t.resume_id;update experience,experience_view set experience.lastjob=1 where experience.id=experience_view.id;drop view experience_view;