–显示全部学生的姓名、班级名和所在院系
select sname 姓名,LEFT(sno,8) 班级名, department 所在院系 from tb_student
–列出学生的政治面貌重复的记录自动去掉
select distinct polity from tb_student
–返回课程表中的前20%的记录
select top 20 percent *from tb_course
–显示课程表中课程号、课程名、先修课(用列别名的三方式显示)
select c_no 课程号,课程名=cname,rcno as 先修课 from tb_course
–列出计算机2班女同学的名单
select *from tb_student where sex='女’and department=‘计算机’and sno like ‘%02%’
–列出年龄不在18岁到20岁之间的所有学生名单
select *from tb_student where year(getdate())-year(birthday) not between 18 and 20
–列出既不是电子系,也不是国际贸易的学生的学号、姓名、和所在院系
select sno,sname,department from tb_student where department not in(‘电子系’,‘国际贸易’)
–列出’苏?步‘的老师名
select *from tb_teacher where sn like ‘苏_步’
–显示学生表中19岁以上女同学的信息
select *from tb_student where year(getdate())-year(birthday)>19 and sex=‘女’
–查询1998年以后出生的学生信息
select *from tb_student where YEAR(birthday)>1998
–在成绩表中查询成绩从70-90分的学生的信息
select *from tb_score where grade between 70 and 90
–查询学生表中姓张和姓王的同学
select *from tb_student where left(sname,1) in(‘张’,‘王’)
–学生表中找到所有姓李名lan(蓝/兰/阑)的同学
select *from tb_student where sname like’李名[蓝兰阑]’
–学生表中找到所有不姓张的同学
select *from tb_student where LEFT(sname,1) not in(‘张’)
数据库中select语言
最新推荐文章于 2024-04-09 21:28:18 发布