首先创建表:
CREATE TABLE score_t(
name VARCHAR(10),
subject VARCHAR(10),
score INT(10)
);
插入数据:
INSERT INTO score_t VALUES
("张三","java",71),
("李四","java",82),
("王五","java",90),
("赵六","java",98),
("孙七","java",90),
("张三","python",81),
("李四","python",92),
("王五","python",93),
("赵六","python",97),
("孙七","python",70);
思路:
这里只需要先将T2表数据按科目和分数,去重,再查找满足比它分数高的记录数 < 3 的数据即可。
查询各科成绩前三名,前三名都有一个特点,比他们成绩高的人数小于3,成绩就是前三名。
正确写法:
摘自:https://blog.csdn.net/weixin_44497013/article/details/107317719