sql语句写法
UPDATE uke_hwork_upload set teacher_name = case id
when 787513 then '张衡璇' when 866956 then '田璐' end where id in (787513,866956)
数据量多一点的:
UPDATE uke_hwork_upload set teacher_name = case teacher_id when 0 then '学堂'
when 923198 then '安卓1' when 1325974524 then '张娟12' when 1326311601 then '张化学'
when 1326311603 then '张化2' when 1326312334 then '白丽娜45'
when 1326312413 then 'ziming班主任' when 1326312431 then '洪燕班主任'
when 1326312443 then '洪燕班主任2' when 1326312444 then '洪燕班主任3'
when 1326312454 then '周启信班主任' when 1326312487 then '自动化测试班主任'
when 1326312490 then '张班2' when 1326313005 then '白丽娜1' when 1326313012 then '丽丽白'
when 1326313616 then '孙继班主任数学' when 1326347790 then '班主任1号'
when 1326358624 then '000002' when 1326397477 then '班主任1011'
when 1326397662 then '班主任1012' when 1326397669 then '班主任1013'
when 1426325507 then '越前前的班主任' when 1426409574 then '15300000006'
when 1426549759 then '金牌老师4' when 1426549759 then '学堂'
end where teacher_id in ( 1325974937 , 0 , 1325974524 , 1326313616 ,
1326312431 , 1326311601 , 1326313012 , 1326312334 , 1326312443 ,
1326312490 , 1326312487 , 1326313005 , 1326312413 , 923198 ,
1326311603 , 5001914586 , 1326312444 , 1326312454 , 5001914524 ,
32326319149 , 32326319216 , 32326319215 , 32326319323 , 32326319547 ,
1326347790 , 1326397477 , 1426325426 , 1426325507 , 1326358624 ,
1326397662 , 1426325420 , 1426549759 , 1426683043 , 1326397669 ,
1426409574 , 1426798396 , 1426723061 , 1426794045 )
and correct_time < '2019-12-01' and correct_time > '2019-11-01'
mybatis中写法
<update id="updateTeacherNameByTeacherId">
UPDATE uke_hwork_upload set teacher_name =
<foreach collection="idNameVoList" item="idName" index="index" separator=" "
open="case teacher_id" close="end">
when #{idName.tutorId} then #{idName.tutorName}
</foreach>
where teacher_id in (
<foreach collection="teacherIdList" item="teacherId" separator=",">
#{teacherId}
</foreach>
)
and correct_time < #{endDate}
and correct_time > #{startDate}
</update>
1: idNameVoList是 List<TutorIdNameVo> idNameVoList 的集合
@Data
public class TutorIdNameVo {
//班主任id
private Long tutorId;
//班主任姓名
private String tutorName;
}