009--MySQL面试题

009--MySQL面试题_第1张图片
Paste_Image.png

1.查询Java课程的学生姓名和学号

select stu.no,stu.name 
from 
table_student stu 
inner join table_sc sc on sc.no = stu.no
inner join table_course cou on sc.number = cou.number
where upper(cou.coursename) = 'JAVA'

2.依依的选修课名称

select cou.coursename
from 
table_course cou 
inner join table_student stu on stu.number = stu.number

3.选修5门课的学生

select stu.no,stu.name 
from 
table_student stu 
inner join (select score.no,count(score.no) noCount from table_sc score GROUP BY score.no ) tempSc on tempSc.no = stu.no
where tempSc.noCount=5

4.分页查询1-5

SELECT stu.* 
FROM table_student stu 
LIMIT 0,5

5.成绩排序,五页一条,查第二页

SELECT sc.* 
FROM table_sc sc 
Order by sc.chengJi
LIMIT 5,5

6.每个班级成绩最好的学生姓名和成绩

select stu.no,stu.name 
from 
table_student stu 
where stu.no in (select sc.no from table_sc sc where sc.chengJi = Max(sc.chengJi) GROUP BY score.number)

7.取出当前时间

SELECT DATE_FORMAT(NOW(),'%Y%m%d%H%i%s') 

你可能感兴趣的:(009--MySQL面试题)