mysql 有用的查询

 数据:

1.把分数最好的学生的成绩减去1分(更新某个最大值的项目)

UPDATE student a ,(SELECT MAX(score) score FROM student) b set a.score = a.score - 1 WHERE a.score = b.score;

 2.查询每个学生所有课程中分数最高的课程 (查询所有分组中某个值最大的项)

select a.name,a.className,a.score from (SELECT id,name,className,max(score) score from student s GROUP BY name) b
INNER JOIN student a on a.name = b.name where a.score = b.score

猜你喜欢

转载自luhantu.iteye.com/blog/2419618