sql 实例
1001 查询全体男同学信息情况
select * from student where sex='男'
1002 查询选修了 1 号课的学生的学号和成绩
select sno,grade from sc where cno='1'
1003 查询 1989 年以前出生的学生学号和姓名和出生日期(提示请用 year(csrq)函数来取出生年
号再与 1989 比较)
select sno,sname,csrq from student where year(csrq)<1989
1004 查询信息系所有女生的学号,姓名,及所在系
select sno,sname,sdept from student where sdept='信息系' and sex='女&
#39;
1005 查询课程名是数据库的课程号和学分
select cno,ccredit from course where cname='数据库'
1006 查询先行课号为 5 的课程号和课程名
select cno,cname from course where cpno='5'
1007 查询英语系 90 后的学生情况(注 90 年后出生的)
select * from student where sdept='英语系' and year(csrq)>=1990
1008 查询计算机系或信息系中年龄超过 21 岁的同学情况.(设当前年为 2010 年,提示用当前年减去
出生年再与 21 岁比较)
select * from student where (sdept='计算机系' or sdept='信息系')
and (2010-year(csrq))>21
1009 请将 3 号课及 4 号课学生的学号课程号及成绩显示出来
select sno,cno,grade from sc where cno='3' or cno='4'
1010 查询所有先行课程号为 0 且学分为 2 的课程名,先行课程号,及学分
select cname,cpno,ccredit from course where cpno='0' and ccredit=2
2010 查询学分为 3 以上(不含 3),且课程名中包含着'数据'二字的所有课程名及学分
select cname ,ccredit from course where ccredit>3 and cname like '数
据%'
2001 查询年龄在 20-23 岁之间(含 20 与 23 岁)的学生姓名,系别,年龄(请不要用 between 语
句提交当前年 2010
) select sname,sdept,(2010-year(csrq)) as age from student where (2010-
year(csrq))>=20 and (2010-year(csrq))<=23
评论