看到一道题说在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 当然别的都一样
解决方案 »
- mysql 过滤问题
- MySQL数据库,如何根据已有的SQL语句对数据库进行加压?求思路
- 关于数据库排序问题
- mysql中怎么自定义错误处理?
- jsp+mysql数据库连接内存溢出问题??
- 求教特殊汉字写入数据库的问题
- Mysql5.0, 我用Mysql administrator里edit table设置列的charset为gb2312可以生效,为啥设置table option为gb2312却不生效?
- 请帮我看看这样的设计是否可行?
- 如何一次性更新多条记录?
- Mysql5.7版本,连接上没法操作的问题,急求大神的指点,万分感谢
- 请问怎样建商品表?
- 关于 left join 多表查询的语句,在线求!
select * from student order by math desc limit 1;第三名
select * from student order by math desc limit 2,1;