mysql命令 中级篇

数据库表链接:链接:https://pan.baidu.com/s/1fLOMTnbyrsKCAw35aUtCew 
提取码:1234 

 

普通查询

1、查询学生姓名包含“丽”这个字的学生的所有信息,并按学号排序。

select * from TB_Student where StuName like "%丽%" order by StuID;

2、查询1985年后出生的男生信息。

select * from TB_Student where Sex = 'M' and year(Birthday)>1985;

3、查询平时成绩所占比例超过50%的课程班编号及教师编号。

select CourseClassID,TeacherID from tb_courseclass where CommonPart >50 ;

4、统计课程班为“T080010401”的学生人数。

select count(*) from tb_grade where CourseClassID='T080010401' ;

5.统计课程班为“T080010401”的学生的总评成绩的平均分、最高分及最低分。

select avg(TotalScore),max(TotalScore),min(TotalScore) from tb_grade where CourseClassID='T080010401' ;

6、查询课程班为“T080010401”且总评成绩在“80-90”之间的学生的学号及所有成绩信息,按学号降序排列。

select StuID,CommonScore,MiddleScore,LastScore,TotalScore from tb_grade where CourseClassID='T080010401' and TotalScore>80 and TotalScore<90 order by StuID desc;

7、查询成绩表中所有总评平均成绩大于60的课程号及其平均成绩。

select CourseID,avg(TotalScore) from tb_grade group by CourseID;

联合查询

 

1. 查询电子工程系所有男生的学号、姓名、性别、生日,按生日降序排列。

select StuID,Stuname,Sex,Birthday from tb_student,tb_dept where tb_student.DeptID = tb_dept.DeptID and DeptName = '电子工程系'  order by Birthday desc ;  

2、查找班主任为“陈玲”老师的班级中补考不及格的学生信息,列出学生学号、姓名、课程名、补考成绩。    

select tb_student.StuID,StuName,CourseName ,RetestScore from tb_teacher,tb_course,tb_courseclass,tb_student,tb_grade where tb_teacher. TeacherID = tb_courseclass.TeacherID  and tb_courseclass.CourseID=tb_course.CourseID and tb_grade.CourseClassID =tb_courseclass.CourseClassID and tb_grade.StuID = tb_student.StuID and TeacherName="陈玲" and RetestScore<60;

3、统计各班的补考人次,列出班编号、班名、班主任姓名及补考人次,按补考人次降序排列。

select tb_grade.ClassID,ClassName,TeacherName,count(*) as nums from   tb_grade,tb_class,tb_teacher     where   tb_grade.ClassID = tb_class.ClassID and tb_teacher.TeacherID= tb_class.TeacherID   group by tb_grade.ClassID order by nums desc;

4、查询有二门以上(含二门)低于60分的课程的学生姓名及其平均成绩。

select StuName,av from (select StuID,count(*) as nums,avg(TotalScore) as av from tb_grade where TotalScore < 60  group by StuID) as biao1,tb_student where biao1.StuID = tb_student.StuID and nums>1;

5、统计各个系各个班的总评平均成绩,要求列出系编号、系名、班编号、班名及总评平均成绩,按系编号及班编号升序排列。

select DeptName,tb_dept.DeptID,tb_grade.ClassID,ClassName,avg(TotalScore) from tb_grade,tb_class,tb_dept where tb_class.ClassID =  tb_grade.ClassID   and    tb_dept.DeptID = tb_class.DeptID  group by tb_grade.ClassID order by tb_dept.DeptID;

6、统计每个学生的选课数(包括没有选课的学生),列出学号、姓名、选课门数。

select  tb_student.StuID,StuName,count(*) from tb_selectcourse,tb_student where tb_selectcourse.StuID = tb_student.StuID group by tb_selectcourse.StuID;

7、找出没有选修任何课程的学生的学号、姓名及所在系名。

select StuID,StuName,DeptName from tb_student,tb_dept where tb_student.DeptID=tb_dept.DeptID and StuID not in (select distinct StuID from tb_selectcourse );

 

 

 

 

 

 

 

 

插入中文数据时报错:

可以看看这几篇:

https://blog.csdn.net/qq_43722072/article/details/106957447?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.channel_param

https://blog.csdn.net/daydrawn/article/details/83306138

出现错误ERROR 1366 (HY000),

大致思路,还是去修改一下mysql 的配置信息,将默认编码utf-8  转为 gbk 即可 

1.  show variables like 'character%';     //  查找mysql安装路径

2. 打开my.ini 将 default-character-set 的编码改成   gbk 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值