看到一道题说在10W数据中(学生成绩)用你感觉最高效的语句查询到第一名和第三名
+------+-----------+---------+---------+------+
| id | name | chinese | english | math |
+------+-----------+---------+---------+------+
| 1 | 寮犲皬鏄? | 89 | 78 | 90 |
| 2 | 鏉庤繘 | 67 | 98 | 56 |
| 5 | 鏉庢潵璐? | 82 | 84 | 67 |
| 6 | 寮犺繘瀹? | 55 | 85 | 45 |
| 7 | 榛勮搲 | 75 | 65 | 30 |
+------+-----------+---------+---------+------+-------------------------------------------------------
我用mysql感觉用数据库自带的语句
第一名:select max(math) from student;
第三名:select max(math) from student where math!=(select max(math) from student where math!=(select max(math) from student)) and math!=(select max(math) from student);我知道这肯定不是最高效的!大家发表一下意见!最高效的查询语句这里是mysql 当然别的都一样
+------+-----------+---------+---------+------+
| id | name | chinese | english | math |
+------+-----------+---------+---------+------+
| 1 | 寮犲皬鏄? | 89 | 78 | 90 |
| 2 | 鏉庤繘 | 67 | 98 | 56 |
| 5 | 鏉庢潵璐? | 82 | 84 | 67 |
| 6 | 寮犺繘瀹? | 55 | 85 | 45 |
| 7 | 榛勮搲 | 75 | 65 | 30 |
+------+-----------+---------+---------+------+-------------------------------------------------------
我用mysql感觉用数据库自带的语句
第一名:select max(math) from student;
第三名:select max(math) from student where math!=(select max(math) from student where math!=(select max(math) from student)) and math!=(select max(math) from student);我知道这肯定不是最高效的!大家发表一下意见!最高效的查询语句这里是mysql 当然别的都一样
select * from student order by math desc limit 1;第三名
select * from student order by math desc limit 2,1;