目录
需求
SQL实现
知识点参考
需求:
表长这样:
分析:也就是说要按给定的规则更新rank列的值
SQL如下:
update member set `rank`=case
when score>=0 and score<100 THEN 0
when score>=100 and score<200 THEN 1
when score>=200 and score<300 THEN 2
when score>=300 and score<400 THEN 3
when score>=400 and score<500 THEN 4
when score>=500 THEN 5
end
注意:rank是mysql中的关键字,它作为字段名称在sql语句中出现的话要用 ` 转义