Auto commit
This commit is contained in:
parent
d59764c856
commit
669136154c
@ -407,16 +407,45 @@ FROM (
|
||||
)s3;
|
||||
|
||||
#19.查询每门课程被选修的学生数
|
||||
|
||||
SELECT c.`name`, COUNT(*)
|
||||
FROM courses c
|
||||
LEFT JOIN scores sc ON sc.course_id = c.id
|
||||
GROUP BY c.id;
|
||||
#20.查询出只选修两门课程的学生学号和姓名
|
||||
SELECT st.id, st.`name`
|
||||
FROM students st
|
||||
WHERE (
|
||||
SELECT COUNT(*)
|
||||
FROM scores sc
|
||||
WHERE sc.student_id = st.id
|
||||
)=2;
|
||||
|
||||
#21.查询男生、女生人数
|
||||
SELECT st.gender, COUNT(*)
|
||||
FROM students st
|
||||
GROUP BY st.gender;
|
||||
|
||||
SELECT COUNT(IF(st.gender='男', TRUE, NULL)) '男生人数',
|
||||
COUNT(IF(st.gender='女', TRUE, NULL)) '女生人数'
|
||||
FROM students st;
|
||||
|
||||
#22.查询名字中含有「风」字的学生信息
|
||||
SELECT *
|
||||
FROM students st
|
||||
WHERE st.`name` LIKE '%风%';
|
||||
|
||||
|
||||
#23.查询同名同性学生名单,并统计同名人数
|
||||
SELECT s.`name`, s.gender, COUNT(*)
|
||||
FROM students s
|
||||
GROUP BY s.`name`, s.gender
|
||||
HAVING COUNT(*) > 1;
|
||||
|
||||
|
||||
#24.查询 1990 年出生的学生名单
|
||||
SELECT *
|
||||
FROM students s
|
||||
WHERE YEAR(s.birth) = 1990;
|
||||
|
||||
#25.查询每门课程的平均成绩,结果按平均成绩降序排列,平均成绩相同时,按课程编号升序排列
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user