![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
mysql练习
文章平均质量分 85
一只楠喃
一只大数据路上的程序媛️BUT目前处于自动驾驶仿真行业
展开
-
掌握这些MySQL函数,你就是MySQL大神!
文章目录一、MySQL 字符串函数二、MySQL 数字函数三、MySQL日期函数四、MySQL 高级函数一、MySQL 字符串函数函数描述实例ASCII(s)返回字符串 s 的第一个字符的 ASCII 码。返回 CustomerName 字段第一个字母的 ASCII 码 . (SELECT ASCII(CustomerName) AS NumCodeOfFirstCharFROM Customers;)CHAR_LENGTH(s)返回字符串 s 的原创 2021-06-23 11:28:08 · 198 阅读 · 0 评论 -
– 12、查询至少有一门课与学号为“01“的同学所学相同的同学的信
– 12、查询至少有一门课与学号为"01"的同学所学相同的同学的信SELECT st.*FROMstudent stWHERE st.s_id IN(SELECTDISTINCT sc.s_idFROM score scWHEREsc.c_id IN (SELECT sc.c_idFROM score scWHERE sc.s_id = '01'))原创 2020-10-06 11:52:12 · 39585 阅读 · 0 评论 -
– 11、查询没有学全所有课程的同学的信息
– 11、查询没有学全所有课程的同学的信息SELECT st.*FROM student stLEFT JOIN score sc1 ON sc1.s_id=st.s_id AND sc1.c_id='01'LEFT JOIN score sc2 ON sc2.s_id=st.s_id AND sc2.c_id='02'LEFT JOIN score sc3 ON sc3.s_id=st.s_id AND sc3.c_id='03'WHERE sc1.s_score IS NULL OR sc2原创 2020-10-06 11:51:41 · 40115 阅读 · 0 评论 -
– 10、查询学过编号为“01“但是没有学过编号为“02“的课程的同学的信息
– 10、查询学过编号为"01"但是没有学过编号为"02"的课程的同学的信息SELECT st.*FROM student stWHERE st.s_id IN(SELECT sc.s_id FROM score sc WHERE sc.c_id='01') AND st.s_id NOT IN (SELECT sc.s_id FROM score sc WHERE sc.c_id='02' ) ...原创 2020-10-05 20:08:08 · 42905 阅读 · 0 评论 -
– 8、查询没学过“张三“老师授课的同学的信息
– 8、查询没学过"张三"老师授课的同学的信息SELECT st.*FROM student stWHERE st.s_id NOT IN(SELECT sc.s_id FROM score sc WHERE sc.c_id IN (SELECT c.c_id FROM course c,teacher t WHERE c.t_id=t.t_id AND t.t_name='张三'))原创 2020-10-05 18:10:51 · 42321 阅读 · 0 评论 -
7、查询学过“张三“老师授课的同学的信息
7、查询学过"张三"老师授课的同学的信息SELECT st.*FROM student stWHERE st.s_id IN(SELECT sc.s_id FROM score sc WHERE sc.c_id IN (SELECT c.c_id FROM course c,teacher t WHERE c.t_id=t.t_id AND t.t_name='张三'))原创 2020-10-05 18:10:03 · 42205 阅读 · 0 评论 -
– 6、查询“李“姓老师的数量
– 6、查询"李"姓老师的数量SELECT COUNT(t.t_name)FROM teacher tGROUP BY t.t_name HAVINGt.t_name LIKE '李%'原创 2020-10-05 18:09:23 · 43698 阅读 · 0 评论 -
5、查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩
5、查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩SELECT st.s_id,st.s_name,c,sFROM student stLEFT JOIN(SELECT sc.s_id,COUNT(sc.c_id) c,SUM(sc.s_score) s FROM score scGROUP BY sc.s_id) d ON st.s_id=d.s_id...原创 2020-10-05 18:08:32 · 46507 阅读 · 0 评论 -
4、查询平均成绩小于60分的同学的学生编号和学生姓名和平均成绩 – (包括有成绩的和无成绩的)
4、查询平均成绩小于60分的同学的学生编号和学生姓名和平均成绩– (包括有成绩的和无成绩的)SELECT st.s_id, st.s_name,CASE WHEN AVG(sc.s_score) IS NULL THEN '无' ELSE ROUND (AVG(sc.s_score) ,2) END AS '平均分'FROM student stLEFT JOIN score scON sc.s_id=st.s_idGROUP BY st.s_id HAVING AVG(sc.s_sco原创 2020-10-05 18:07:48 · 43619 阅读 · 0 评论 -
3、查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩
3、查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩SELECTst.s_id,st.s_name,ROUND (AVG(sc.s_score),2)FROM student st JOIN score sc ON st.s_id=sc.s_idGROUP BY st.s_id HAVING AVG(sc.s_score)>=60;原创 2020-10-05 18:07:08 · 46183 阅读 · 0 评论 -
2、查询“01“课程比“02“课程成绩低的学生的信息及课程分数
2、查询"01"课程比"02"课程成绩低的学生的信息及课程分数SELECT st.*,sc.s_score AS '语文',sc2.s_score AS '数学FROM student st LEFT JOIN score sc ON sc.s_id=st.s_id AND sc.c_id='01' LEFT JOIN score sc2 ON sc2.s_id=st.s_id AND sc2.c_id='02'WHERE sc.s_score < sc2.s_score..原创 2020-10-05 18:05:33 · 40065 阅读 · 0 评论 -
1、查询“01“课程比“02“课程成绩高的学生的信息及课程分数
1.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_id,c_name,t_id) – –课程编号, 课程名称, 教师编号 –3.教师表 Teacher(t_id,t_name) –教师编号,教师姓名 –4.成绩表 Score(s_id,c_id,s_score) –学生编号,课程编号,分数CREATE TABLE student(s_id VARCHAR(20),s_name VARCHAR(2原创 2020-10-05 18:04:30 · 44670 阅读 · 0 评论 -
mysql练习(45)学生成绩教师综合查询
– 1、查询"01"课程比"02"课程成绩高的学生的信息及课程分数SELECT st.*,sc.s_score AS '语文',sc2.s_score AS '数学'FROM student st LEFT JOIN score sc ON sc.s_id=st.s_id AND sc.c_id='01' LEFT JOIN score sc2 ON sc2.s_id=st.s_id AND sc2.c_id='02'WHERE sc.s_score>sc2.s_score–原创 2020-09-29 16:48:15 · 41435 阅读 · 2 评论