登录
首页 >  数据库 >  MySQL

mysql初级练习题以及题目

来源:SegmentFault

时间:2023-01-25 08:48:53 171浏览 收藏

来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习数据库相关编程知识。下面本篇文章就来带大家聊聊《mysql初级练习题以及题目》,介绍一下MySQL,希望对大家的知识积累有所帮助,助力实战开发!

image.png

1.查询英语分数在 80-90之间的同学。

SELECT stu_id
FROM exam
WHERE score >=80 AND score 

2.查询数学分数为89,90,91的同学。

SELECT * FROM student WHERE stu_no IN(
    SELECT stu_id FROM exam WHERE  score  IN(89,90,91) 
    AND  sub_id = (
        SELECT subject_id FROM `subject` WHERE subject_name = '数学'
    )
)

3.查询所有姓李的学生成绩。

SELECT * FROM exam WHERE  stu_id IN (
    SELECT stu_no FROM student WHERE stuname LIKE "李%"
)

4.查询数JAVA>80 并且 HTML分>80的同学的信息。

SELECT stu_id , COUNT(*) FROM exam e , `subject` s 
WHERE e.sub_id= s.subject_id AND 

(
    (e.score >= 80 AND s.subject_name='JAVA')   
    OR
    (e.score >= 90 AND s.subject_name='HTML')
)
GROUP BY stu_id HAVING COUNT(*) = 2

5.对数学成绩排序后输出。

SELECT s.stu_name,e.score
FROM student s INNER JOIN exam e ON s.student_no=e.stu_id INNER
JOIN `subject` k ON e.sub_id=k.subject_id WHERE `subject_name`='JAVA' 
ORDER BY e.score ASC;

6.对总分排序后输出,然后再按从高到低的顺序输出

SELECT s.stu_name , SUM(e.score)
FROM student s INNER JOIN exam e ON s.student_no=e.stu_id 
 GROUP BY e.stu_id ORDER BY SUM(e.score) ASC;

7.对姓李的学生数学成绩排序输出.

SELECT s.stu_name , e.score
FROM student s INNER JOIN exam e ON s.student_no=e.stu_id 
WHERE s.stu_name LIKE '李%' 
AND e.`sub_id`=
        (
           SELECT subject_id FROM `subject` WHERE subject_name='JAVA'
        )

ORDER BY e.`score`;

8.展示学生所有信息与所属年级信息.

SELECT *
FROM student s INNER JOIN grade g ON s.gradeid=g.gradeid

9.展示所有学生的考试信息.(包括学生,考试课程,成绩信息.) 三表内连接.

SELECT *
FROM student s INNER JOIN exam e ON s.student_no=e.stu_id 
INNER JOIN `subject` sub ON e.sub_id=sub.subject_id
INNER JOIN grade g ON s.`gradeid`=g.`gradeid`

10.统计数学成绩大于90的学生有多少个?

SELECT COUNT(*)
FROM student s INNER JOIN exam e ON s.student_no=e.stu_id 
INNER JOIN `subject` sub ON e.sub_id=sub.subject_id
WHERE e.score>90 AND sub.subject_name='JAVA'

文中关于mysql的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《mysql初级练习题以及题目》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表