--1、查询"01"课程比"02"课程成绩高的学生的信息及课程分数
SELECTa.*, b.s_score ASscore1,
c.s_scoreASscore2FROMstudent aLEFT JOIN score b ON a.s_id =b.s_idAND b.c_id = '01'
LEFT JOIN score c ON a.s_id =c.s_idAND (c.c_id = '02' OR c.c_id =NULL)WHEREb.s_score>c.s_score ;--2、查询"01"课程比"02"课程成绩低的学生的信息及课程分数
SELECTa.*, b.s_score ASscore1,
c.s_scoreASscore2FROMstudent aLEFT JOIN score b ON a.s_id =b.s_idAND (b.c_id = '01' OR b.c_id =NULL)LEFT JOIN score c ON a.s_id =c.s_idAND c.c_id = '02'WHEREb.s_score
SELECTa.s_id,
a.s_name,ROUND(AVG(b.s_score), 1) AS平均成绩FROMstudent aLEFT JOIN score b ON a.s_id =b.s_idGROUP BYa.s_idHAVINGAVG(b.s_score) >= 60;--4、查询平均成绩小于60分的同学的学生编号和学生姓名和平均成绩--(包括有成绩的和无成绩的)--方法一:
SELECTa.s_id,
a.s_name,ROUND(AVG(b.s_score), 1) AS平均成绩FROMstudent aLEFT JOIN score b ON a.s_id =b.s_idGROUP BYa.s_idHAVINGAVG(b.s_score) < 60
ORa.s_idNOT IN(SELECT DISTINCT a.s_id FROM student a JOIN score b WHERE a.s_id=b.s_id);--方法二:
SELECTa.s_id,a.s_name,ROUND(AVG(b.s_score),2) ASavg_scoreFROMstudent aJOIN score b ON a.s_id =b.s_idGROUP BYa.s_idHAVING AVG(b.s_score) < 60
UNION
SELECT a.s_id,a.s_name,0 AS avg_score FROMstudent aWHERE a.s_id NOT IN (SELECT DISTINCT s_id FROMscore);--5、查询所有同学的学生编号、学生姓名、选课总数、所有课程的总成绩,并从高到低排序
SELECTa.s_id,
a.s_name,COUNT(b.c_id) AS选课总数 ,SUM(b.s_score) AS总成绩FROMstudent aLEFT JOINscore bONa.s_id=b.s_idGROUP BYa.s_idORDER BY SUM(b.s_score) DESC;--6、查询"李"姓老师的数量
SELECT COUNT(t_id) FROM teacher WHERE t_name LIKE '李%';--7、查询学过"张三"老师授课的同学的信息
#张三编号SELECT t_id FROM teacher WHERE t_name = '张三'#张三代课的课程编号SELECT c_id FROM course WHERE t_id = (SELECT t_id FROM teacher WHERE t_name = '张三')
#学张三课程的学生编号SELECT s_id FROM score WHERE c_id = (SELECT c_id FROM course WHERE t_id = (SELECT t_id FROM teacher WHERE t_name = '张三'))--方法一:
SELECT *FROM student WHEREs_idIN (SELECT s_id FROM score WHEREc_id= (SELECT c_id FROM course WHEREt_id= (SELECT t_id FROM teacher WHERE t_name = '张三'))
);--方法二:
SELECT a.* FROMstudent aJOIN score b ON a.s_id =b.s_idWHEREb.c_idIN (SELECT c_id FROM course WHERE t_id = (SELECT t_id FROM teacher WHERE t_name = '张三'));--8、查询没学过"张三"老师授课的同学的信息--方法一:
SELECT *FROM student WHEREs_idNOT IN (SELECT s_id FROM score WHEREc_id= (SELECT c_id FROM course WHEREt_id= (SELECT t_id FROM teacher WHERE t_name = '张三'))
);--9、查询学过编号为"01"并且也学过编号为"02"的课程的同学的信息,及两门课程成绩--方法一
SELECTa.*, b.s_score,
c.s_scoreFROMstudent aJOIN score b ON a.s_id =b.s_idAND b.c_id = '01'
JOIN score c ON a.s_id =c.s_idAND c.c_id = '02';--方法二:
SELECTa.*, b.s_score,
c.s_scoreFROMstudent a,
score b,
score cWHEREa.s_id=b.s_idAND a.s_id =c.s_idAND b.c_id = '01'
AND c.c_id = '02';--10、查询学过编号为"01"但是没有学过编号为"02"的课程的同学的信息
SELECT s_id FROM score WHERE c_id = '01'
SELECT s_id FROM score WHERE c_id = '02'
SELECT *FROMstudent aWHEREa.s_idIN (SELECT s_id FROM score WHERE c_id = '01')AND a.s_id NOT IN (SELECT s_id FROM score WHERE c_id = '02');--11、查询没有学全所有课程的同学的信息
SELECT s_id FROMscoreGROUP BYs_idHAVING COUNT(s_id) != 3#方法一:SELECT *FROM student WHERE s_id IN(SELECT s_id FROMscoreGROUP BYs_idHAVING COUNT(s_id) != 3);
#方法二:SELECT a.s_id FROMscore aJOIN score b ON a.s_id=b.s_id AND b.c_id='02'JOIN score c ON a.s_id=c.s_id AND c.c_id='03'WHERE a.c_id='01'
SELECT *FROM student d WHERE d.s_id IN(SELECT e.s_id FROM score e WHERE e.s_id NOT IN(SELECT a.s_id FROMscore aJOIN score b ON a.s_id=b.s_id AND b.c_id='02'JOIN score c ON a.s_id=c.s_id AND c.c_id='03'WHERE a.c_id='01')
);
#--------------
# 上述两种方法结果都少了没有选课的8号学生,但看具体条件是否需要查出
# 学全选取所有课程的同学的idSELECT s_id FROMscoreGROUP BYs_idHAVING COUNT(s_id) = 3#方法一:SELECT *FROM student WHERE s_id NOT IN(SELECT s_id FROMscoreGROUP BYs_idHAVING COUNT(s_id) = 3);--12、查询至少有一门课与学号为"01"的同学所学相同的同学的信息
SELECT c_id FROM score WHERE s_id ='01'
SELECT DISTINCT s_id FROM score WHERE c_id IN (SELECT c_id FROM score WHERE s_id ='01')SELECT * FROMstudent aWHEREa.s_idIN (SELECT DISTINCT b.s_id FROM score b WHEREb.c_idIN (SELECT c.c_id FROM score c WHERE c.s_id ='01')
);--13、查询和"01"号的同学学习的课程完全相同的其他同学的信息
SELECT * FROM student WHERE s_id IN(SELECT DISTINCT s_id FROM score WHERE s_id!='01' AND c_id IN (SELECT c_id FROM score WHERE s_id ='01')GROUP BYs_idHAVING COUNT(1)=(SELECT COUNT(1) FROM score WHERE s_id='01')
)--15、查询两门及其以上不及格课程的同学的学号,姓名及其平均成绩
SELECT s_id FROM score WHERE s_score<60 GROUP BY s_id HAVING COUNT(1) >= 2
SELECTa.s_id,
a.s_name,ROUND(AVG(b.s_score), 1) AS平均成绩FROMstudent aLEFT JOIN score b ON a.s_id =b.s_idGROUP BYa.s_idHAVINGa.s_idIN(SELECT s_id FROM score WHERE s_score<60 GROUP BY s_id HAVING COUNT(1) >= 2)--16、检索"01"课程分数小于60,按分数降序排列的学生信息及01分数--方法一:
SELECTa.*, b.s_scoreFROMstudent aLEFT JOIN score b ON a.s_id =b.s_idWHEREb.c_id= '01'
AND b.s_score < 60
ORDER BYb.s_scoreDESC;--方法二:
SELECTa.*, b.s_scoreFROMstudent a,score bWHEREa.s_id= b.s_id AND b.c_id='01' AND b.s_score < 60
ORDER BYb.s_scoreDESC;--方法三(有点瑕疵):
SELECTa.*, b.s_scoreFROMstudent aLEFT JOIN score b ON a.s_id =b.s_idAND b.c_id = '01'
AND b.s_score < 60
ORDER BYb.s_scoreDESC;--17、按平均成绩从高到低显示所有学生的所有课程的成绩以及平均成绩
--方法一(自连接):
SELECTa.s_id,
(SELECT s_score FROM score WHERE s_id=a.s_id AND c_id='01') ASscore1,
(SELECT s_score FROM score WHERE s_id=a.s_id AND c_id='02') ASscore2,
(SELECT s_score FROM score WHERE s_id=a.s_id AND c_id='03') ASscore3,ROUND(avg(a.s_score), 2) AS平均分FROMscore aGROUP BYa.s_idORDER BY 平均分 DESC;--方法二(自连接):
SELECTa.s_id,
b.s_score,
c.s_score,
d.s_score,ROUND(avg(a.s_score), 2) AS平均分FROMscore aLEFT JOIN score b ON a.s_id = b.s_id AND b.c_id='01'
LEFT JOIN score c ON a.s_id = c.s_id AND c.c_id='02'
LEFT JOIN score d ON a.s_id = d.s_id AND d.c_id='03'
GROUP BYa.s_idORDER BY 平均分 DESC;--18.查询各科成绩最高分、最低分和平均分:以如下形式显示:课程ID,课程name,最高分,最低分,平均分,及格率,中等率,优良率,优秀率--及格为>=60,中等为:70-80,优良为:80-90,优秀为:>=90
SELECTa.c_id,MAX(a.s_score),MIN(a.s_score),AVG(a.s_score)FROMscore aGROUP BYa.c_id;--方法一:
SELECTa.c_idAS课程ID,
b.c_nameAS课程name,MAX(a.s_score) AS最高分,MIN(a.s_score) AS最低分,ROUND(AVG(a.s_score),2) AS平均分,ROUND(100*(SUM(CASE WHEN a.s_score >= 60 THEN 1 ELSE 0 END) / COUNT(1)) , 2) AS '及格率',ROUND(100*(SUM(CASE WHEN a.s_score >= 70 AND a.s_score <80 THEN 1 ELSE 0 END) / COUNT(1)) , 2) AS '中等率',ROUND(100*(SUM(CASE WHEN a.s_score >= 80 AND a.s_score <90 THEN 1 ELSE 0 END) / COUNT(1)) , 2) AS '优良率',ROUND(100*(SUM(CASE WHEN a.s_score >= 90 THEN 1 ELSE 0 END) / COUNT(1)) , 2) AS '优秀率'
FROMscore aLEFT JOIN course b ON a.c_id =b.c_idGROUP BYb.c_id;--19、按各科成绩进行排序,并显示排名--mysql没有rank顺序函数
selecta.s_id,a.c_id,@i:=@i +1 asi保留排名,@k:=(case when @score=a.s_score then @k else @i end) asrank不保留排名,@score:=a.s_score asscorefrom(select s_id,c_id,s_score from score WHERE c_id='01' GROUP BY s_id,c_id,s_score ORDER BY s_score DESC)a,(select @k:=0,@i:=0,@score:=0)sunionselecta.s_id,a.c_id,@i:=@i +1 asi,@k:=(case when @score=a.s_score then @k else @i end) asrank,@score:=a.s_score asscorefrom(select s_id,c_id,s_score from score WHERE c_id='02' GROUP BY s_id,c_id,s_score ORDER BY s_score DESC)a,(select @k:=0,@i:=0,@score:=0)sunionselecta.s_id,a.c_id,@i:=@i +1 asi,@k:=(case when @score=a.s_score then @k else @i end) asrank,@score:=a.s_score asscorefrom(select s_id,c_id,s_score from score WHERE c_id='03' GROUP BY s_id,c_id,s_score ORDER BY s_score DESC)a,(select @k:=0,@i:=0,@score:=0)s--20、查询学生的总成绩并进行排名
SELECTa.s_id,@i:=@i+1 ASi,@k:=(CASE WHEN @score=a.sum_score THEN @k ELSE @i END) ASrank,@score:=a.sum_score ASscoreFROM (SELECT s_id,SUM(s_score) AS sum_score FROM score GROUP BY s_id ORDER BY sum_score DESC) ASa,
(SELECT @i:=0,@score:=0) ASb--21、查询不同老师所教不同课程平均分从高到低显示
SELECTa.t_name,
b.c_id,
b.c_name,ROUND(AVG(c.s_score) ,2) AS平均分FROMteacher aLEFT JOIN course b ON a.t_id =b.t_idLEFT JOIN score c ON b.c_id=c.c_idGROUP BYc.c_idORDER BY AVG(c.s_score) DESC;--22、查询所有课程的成绩第2名到第3名的学生信息及该课程成绩
SELECT c.*,d.s_name,d.s_birth,d.s_sex FROM(SELECT a.s_id,a.s_score,a.c_id,@i:=@i+1 AS 排名 FROM score a,(SELECT @i:=0)b WHERE a.c_id='01') cLEFT JOIN student d ON c.s_id=d.s_idWHERE 排名 BETWEEN 2 AND 3
UNION
SELECT c.*,d.s_name,d.s_birth,d.s_sex FROM(SELECT a.s_id,a.s_score,a.c_id,@j:=@j+1 AS 排名 FROM score a,(SELECT @j:=0)b WHERE a.c_id='02') cLEFT JOIN student d ON c.s_id=d.s_idWHERE 排名 BETWEEN 2 AND 3
UNION
SELECT c.*,d.s_name,d.s_birth,d.s_sex FROM(SELECT a.s_id,a.s_score,a.c_id,@k:=@k+1 AS 排名 FROM score a,(SELECT @k:=0)b WHERE a.c_id='03') cLEFT JOIN student d ON c.s_id=d.s_idWHERE 排名 BETWEEN 2 AND 3;--23、统计各科成绩各分数段人数:课程编号,课程名称,[100-85],[85-70],[70-60],[0-60]及所占百分比
SELECTa.c_idAS 课程编号, a.c_name AS课程名称,
c.`[100-85]的人数`, c.`[100-85]所占百分比`,
d.`[85-70]的人数`, d.`[85-70]所占百分比`,
e.`[70-60]的人数`, e.`[70-60]所占百分比`,
f.`[0-60]的人数`, f.`[0-60]所占百分比`FROMcourse aLEFT JOIN score b ON a.c_id =b.c_idLEFT JOIN(SELECT *,SUM(CASE WHEN s_score >85 AND s_score <=100 THEN 1 ELSE 0 END) AS '[100-85]的人数',ROUND(SUM(CASE WHEN s_score >85 AND s_score <=100 THEN 1 ELSE 0 END)/COUNT(1)*100,2) AS '[100-85]所占百分比'FROM score GROUP BY c_id) c ON a.c_id=c.c_idLEFT JOIN(SELECT*,SUM(CASE WHEN s_score >70 AND s_score <=85 THEN 1 ELSE 0 END) AS '[85-70]的人数',ROUND(SUM(CASE WHEN s_score >70 AND s_score <=85 THEN 1 ELSE 0 END)/COUNT(1)*100,2) AS '[85-70]所占百分比'FROM score GROUP BY c_id) d ON a.c_id=d.c_idLEFT JOIN(SELECT*,SUM(CASE WHEN s_score >60 AND s_score <=70 THEN 1 ELSE 0 END) AS '[70-60]的人数',ROUND(SUM(CASE WHEN s_score >60 AND s_score <=70 THEN 1 ELSE 0 END)/COUNT(1)*100,2) AS '[70-60]所占百分比'FROM score GROUP BY c_id) e ON a.c_id=e.c_idLEFT JOIN(SELECT *,SUM(CASE WHEN s_score >0 AND s_score <=60 THEN 1 ELSE 0 END) AS '[0-60]的人数',ROUND(SUM(CASE WHEN s_score >0 AND s_score <=60 THEN 1 ELSE 0 END)/COUNT(1)*100,2) AS '[0-60]所占百分比'FROM score GROUP BY c_id) f ON a.c_id=f.c_idGROUP BYa.c_id--24、查询学生平均成绩及其名次
SELECTb.s_id,@i:=@i+1 AS相同分数的不同名次,@k:=(CASE WHEN @avg_s=b.avg_score THEN @k ELSE @i END) AS相同分数的相同名次,@avg_s:=b.avg_score AS平均成绩FROM(SELECTa.s_id,ROUND(AVG(a.s_score), 2) ASavg_scoreFROMscore aGROUP BYa.s_idORDER BY AVG(a.s_score) DESC) b,(SELECT @i:=0,@avg_s:=0,@k:=0) c--24.1添加名次rank,(相同分数的相同名次,并列排名)--上面24难以看出并列排名
SELECTb.s_id, b.c_id,--顺序一直在变大
@i:=@i+1 AS相同分数的不同名次,--只有在前后二次分数不同时才会使用顺序号
@k:=(CASE WHEN @s=b.s_score THEN @k ELSE @i END) AS相同分数的相同名次,@s:=b.s_score AS成绩FROM(SELECT *FROM score WHERE s_id='03' ORDER BY s_score DESC)b,
(SELECT @i:=0,@k:=0,@s:=0);--25、查询各科成绩前三名的记录--1.选出b表比a表成绩大的所有组--2.选出比当前id成绩大的 小于三个的--SELECT a.s_id,a.c_id,a.s_score FROM score a--LEFT JOIN score b ON a.c_id=b.c_id AND a.s_score
--26、查询每门课程被选修的学生数
SELECT c_id,COUNT(1) FROM score GROUP BYc_id--27、查询出只有两门课程的全部学生的学号和姓名--方法一:
SELECT a.s_id,a.s_name FROMstudent aLEFT JOIN score b ON a.s_id=b.s_idGROUP BYa.s_idHAVING COUNT(1)=2
--方法二:
SELECT a.s_id,a.s_name FROM student a WHERE a.s_id IN(SELECT s_id FROM score GROUP BY s_id HAVING COUNT(1)=2)--28、查询男生、女生人数
SELECT s_sex,COUNT(1) FROM student GROUP BYs_sex--29、查询名字中含有"风"字的学生信息
SELECT *FROM student WHERE s_name LIKE '%风%'--30、查询同名同性学生名单,并统计同名人数
SELECT a.s_name,a.s_sex,COUNT(1) AS 人数 FROMstudent aJOIN student b ON a.s_name=b.s_name AND a.s_sex=b.s_sex AND a.s_id!=b.s_idGROUP BYa.s_name,a.s_sex--31、查询1990年出生的学生名单--方法一
SELECT s_name FROM student WHERE YEAR(s_birth)='1990'
--方法二
SELECT s_name FROM student WHERE s_birth LIKE '1990%'
--32、查询每门课程的平均成绩,结果按平均成绩降序排列,平均成绩相同时,按课程编号升序排列
SELECT c_id,ROUND(avg(s_score),2)FROMscoreGROUP BYc_idORDER BY avg(s_score) DESC,c_id ASC--33、查询平均成绩大于等于85的所有学生的学号、姓名和平均成绩
SELECT a.s_id,a.s_name,ROUND(avg(b.s_score),2) AS 平均成绩 FROMstudent aLEFT JOIN score b ON a.s_id=b.s_idGROUP BYa.s_idHAVING avg(b.s_score) >= 85
--34、查询课程名称为"数学",且分数低于60的学生姓名和分数
SELECT a.s_name,b.s_score FROMstudent aLEFT JOIN score b ON a.s_id=b.s_idWHERE c_id=(SELECT c_id FROM course WHERE c_name='数学')AND b.s_score < 60
--35、查询所有学生的课程及分数情况;--方法一:
SELECT a.s_id,a.s_name,b.s_score,c.s_score,d.s_score FROMstudent aLEFT JOIN score b ON a.s_id=b.s_id AND b.c_id='01'
LEFT JOIN score c ON a.s_id=c.s_id AND c.c_id='02'
LEFT JOIN score d ON a.s_id=d.s_id AND d.c_id='03'
GROUP BYa.s_id--方法二:
SELECTa.s_id,a.s_name,SUM(CASE c.c_name WHEN '语文' THEN b.s_score ELSE 0 END) AS '语文',SUM(CASE c.c_name WHEN '数学' THEN b.s_score ELSE 0 END) AS '数学',SUM(CASE c.c_name WHEN '英语' THEN b.s_score ELSE 0 END) AS '英语',SUM(b.s_score) as '总分'
FROMstudent aLEFT JOIN score b ON a.s_id =b.s_idLEFT JOIN course c ON b.c_id =c.c_idGROUP BYa.s_id,a.s_name--36、查询任何一门课程成绩在70分以上的姓名、课程名称和分数;
SELECT a.s_name,c.c_name,b.s_score FROMstudent aLEFT JOIN score b ON a.s_id=b.s_idLEFT JOIN course c ON b.c_id=c.c_idHAVING b.s_score > 70
--37、查询不及格的学生id,姓名,及其课程名称,分数
SELECT a.s_id,a.s_name,c.c_name,b.s_score FROMstudent aLEFT JOIN score b ON a.s_id=b.s_idLEFT JOIN course c ON b.c_id=c.c_idWHERE b.s_score < 60
--38、查询课程编号为01且课程成绩在80分以上的学生的学号和姓名;
SELECT b.s_id,b.s_name FROMscore aLEFT JOIN student b ON a.s_id=b.s_idWHERE a.c_id='01' AND a.s_score>80
--39、求每门课程的学生人数
SELECT c_id,COUNT(1) FROM score GROUP BYc_id--40、查询选修"张三"老师所授课程的学生中,成绩最高的学生信息及其成绩
SELECT t_id FROM teacher a WHERE a.t_name='张三'
SELECT c_id FROM course b WHERE t_id=(SELECT t_id FROM teacher a WHERE a.t_name='张三')SELECT c.*,d.s_score FROMstudent cLEFT JOIN score d ON c.s_id=d.s_id AND d.c_id=(SELECT c_id FROM course b WHERE t_id=(SELECT t_id FROM teacher a WHERE a.t_name='张三'))HAVING MAX(d.s_score)--41、查询不同课程成绩相同的学生的学生编号、课程编号、学生成绩
SELECT DISTINCTa.s_id,a.c_id,a.s_scoreFROM score a,score b WHERE a.s_score=b.s_score AND a.c_id!=b.c_id--42、查询每门功课成绩最好的前两名--方法一
SELECT *FROM(SELECT a.s_id,a.c_id,a.s_score, @i:=@i+1 as 排名 FROM score a,(SELECT @i:=0)b WHERE a.c_id='01' ORDER BY a.s_score DESC) cWHERE 排名 BETWEEN 1 AND 2
UNION
SELECT *FROM(SELECT a.s_id,a.c_id,a.s_score, @j:=@j+1 as 排名 FROM score a,(SELECT @j:=0)b WHERE a.c_id='02' ORDER BY a.s_score DESC) cWHERE 排名 BETWEEN 1 AND 2
UNION
SELECT *FROM(SELECT a.s_id,a.c_id,a.s_score, @k:=@k+1 as 排名 FROM score a,(SELECT @k:=0)b WHERE a.c_id='03' ORDER BY a.s_score DESC) cWHERE 排名 BETWEEN 1 AND 2
--方法二--SELECT a.s_id,a.c_id,a.s_score FROM score a--WHERE (SELECT COUNT(1) FROM score b WHERE b.c_id=a.c_id AND b.s_score>=a.s_score)<=2 ORDER BY a.c_id
--43、统计每门课程的学生选修人数(超过5人的课程才统计)。要求输出课程号和选修人数,查询结果按人数降序排列,若人数相同,按课程号升序排列
SELECT c_id AS 课程号,COUNT(1) AS 选修人数 FROMscoreGROUP BYc_idHAVING COUNT(1)>5ORDER BY COUNT(1) DESC,c_id--44、检索至少选修两门课程的学生学号
SELECT s_id,COUNT(1) FROM score GROUP BY s_id HAVING COUNT(1)>=2
--45、查询选修了全部课程的学生信息
SELECT COUNT(1) FROMcourseSELECT b.* FROMscore aLEFT JOIN student b ON a.s_id=b.s_idGROUP BYa.s_idHAVING COUNT(1)=(SELECT COUNT(1) FROMcourse)--46、查询各学生的年龄
--按照出生日期来算,当前月日
SELECT s_id,s_birth,(DATE_FORMAT(NOW(),'%Y')-DATE_FORMAT(s_birth,'%Y'))-(CASE WHEN DATE_FORMAT(NOW(),'%m%d')< DATE_FORMAT(s_birth,'%m%d') THEN 1 ELSE 0 END) ASageFROMstudent--47、查询本周过生日的学生--方法一
SELECT * FROM student WHERE WEEK(CURRENT_DATE)=WEEK(s_birth)--方法二
SELECT * FROM student WHERE WEEK(DATE_FORMAT(NOW(),'%Y%m%d'))=WEEK(s_birth)--48、查询下周过生日的学生
SELECT * FROM student WHERE WEEK(DATE_FORMAT(NOW(),'%Y%m%d'))+1=WEEK(s_birth)--49、查询本月过生日的学生
SELECT * FROM student WHERE MONTH(NOW())=MONTH(s_birth)--50、查询下月过生日的学生
SELECT * FROM student WHERE MONTH(NOW())+1=MONTH(s_birth)SELECT DATE_FORMAT(NOW(),'%Y')SELECT DATE_FORMAT(NOW(),'%Y%m%d')