问一个全表扫描的问题?

表 tb_student ,id, name, gender, status;id为主键;
表tb_score,id, student_id, lecture, score;  tb_student的id和tb_score的student_id是相关联的;
要求写出:
1、gender = 男性,lecture = 数学,score > 70且score < 80的信息,需要select出来name,lecture,score;且按照tb_student的id正序且score逆序排序,限制100条数据;
2、会全表查询吗?
3、去掉score排序会全表查询吗?

sql写法:
select t_student.name, lecture, score
from tb_student as t_student
         join tb_score t_score on t_student.id = t_score.student_id
where t_student.gender = '男性'
  and lecture = '数学'
  and score > 70
  and score < 80
order by t_student.id asc, t_score.score desc
limit 100;


请教下,如何才不可以全表扫描???
#笔试题目#
全部评论
马一下😂
点赞 回复
分享
发布于 2021-03-13 12:45
建索引😊
点赞 回复
分享
发布于 2021-03-14 19:37
乐元素
校招火热招聘中
官网直投
如果只对id建了索引的话 不管怎么查都是全表扫描的
点赞 回复
分享
发布于 2021-03-14 20:04
这里分数表和学生表是多对一的关系吧.然后没有建立索引应该是全表查.索引会将指定字段顺序排列.所以默认只有ID是顺序的
点赞 回复
分享
发布于 2021-04-23 10:29

相关推荐

1 4 评论
分享
牛客网
牛客企业服务