难度
简单
题目
写 SQL 查询成绩⼩于 60 分的所有学⽣名单
有两个表student_info和student_result
student_info中有ID、name,student_result中有ID、student_info_id、result
select si.id,si.name,sr.result from student_info si, student_result sr where si.id = sr.student_info_id and sr.result < 60;
假设有两张表:students
(包含 id
和 name
)和 grades
(包含 student_id
和 score
)
grades
表的 student_id
和 score
列上建立索引:CREATE INDEX idx_student_id ON grades(student_id);
CREATE INDEX idx_score ON grades(score);
SELECT DISTINCT s.name
FROM students s
JOIN grades g ON s.id = g.student_id
WHERE g.score < 60;