-
- 查询教师表中教师号在T5到T10之间的所有字段数据:
select * from huang_le_xiang where no between "T10" and "T5"; 
- 查询授课表中 周数为14 的 课程号、教师号、周数、教室号 字段数据
select * from school_teaching_huanglexiang where week=14; 
- 查询授课表中去重后的所有教师号
select distinct teacher_no from school_teaching_huanglexiang; 
- 查询授课表中教室在J栋的所有字段数据,取2-3条

select * from school_teaching_huanglexiang where class_num like "j%" limit 1,2; - 查询课程表中课时数在45,30,50中的所有字段数据
select * from course_huanglexiang where class_hours in("45","30","50"); 
- 查看教师表中工资不等于3000的 姓名、工资、岗位津贴 字段数据
select name,prof,sal,comm from huang_le_xiang where sal!="3000"; 
- 查询教师表中岗位津贴小于1500的 姓名、职称、工资、岗位津贴 字段数据
select * from huang_le_xiang where comm<"1500"; 
- 查询教师表中岗位津贴为空的所有字段数据,按工资从小到大排序
select * from huang_le_xiang where comm is null order by sal asc; 
- 查询课程表中课程号在C3到C7之间的所有字段数据,按课时数从大到小排序

select * from course_huanglexiang where no between "C3" and "C7" order by class_hours desc; - 查询授课表中教室在Y栋2楼的 课程号、教师号、教室号 字段数据,取第一条
select course_no,teacher_no,class_num from school_teaching_huanglexiang where class_num like "Y2%" limit 1; 
- 查询教师表中 工资为2000 的 教师号、职称、工资 字段数据
select name,prof,sal from huang_le_xiang where sal="2000"; 
- 查询教师表中去重后的所有职称
select distinct prof from huang_le_xiang; 
- 查询授课表中教室号在J102,Y104,Y303,J301中的所有字段数据
select * from school_teaching_huanglexiang where class_num in ("J102","Y104","Y303","J301"); 
- 查看课程表中课时数不等于45的 课程号、课程名、周数 字段数据,按周数从小到大排序,取前两条。
select no,name,class_hours from course_huanglexiang where class_hours!=45 order by class_hours limit 2; 
- 查询授课表中周数大于等于50的 课程号、教师号 字段数据
select course_no,teacher_no from school_teaching_huanglexiang where week>=50; 
- 查询课程表中课程名称以字母“M”开头并且课程名称中有“L”字母的所有字段数据
select * from course_huanglexiang where name like "m%l%"; 
- 查询教师表中教师号在T5到T10之间的所有字段数据:
数据库第五次作业-查询数据
于 2022-03-23 09:40:11 首次发布
本文介绍了多种SQL查询语句的使用方法,包括选择特定范围的数据、查找唯一值、过滤特定条件、排序及分页等操作。通过实例展示了如何在教师表、授课表和课程表中进行高效的数据检索。

被折叠的 条评论
为什么被折叠?



