数据库-sql语句-第一次课

题目

1.查询年龄在19-23岁之间(不含19与23岁)的学生姓名,性别,年龄(当前年2010);
2.查询选修过1或3号课程且成绩大于等于75分的所有学生的学号(不许重复);
3.请将选修了2号课或3号课课程的同学情况按课程号升序,成绩降序排序;
4.请将选了1号课程且成绩在70分以上的,学号的末位数为3的同学按成绩降序排序,并将学号,成绩显示出来;
5.查询管理系所有非李姓的2009级同学情况
6.查询所有两字姓名信息系’的张姓同学的姓名,性别与系别;
7.查询名字中第3个字为玲4月4号出生的学生的姓名和学号;
8.查询信息系所有非刘姓的、名字所有字为3个字的同学的学号和姓名;
9.查询8月8日出生的90后学生的名字及生日(注含1990);
10.查询2009级计算机系男生李姓85年后出生的学生情况"

答案

1011 select sname,sex,2010-year(csrq) as age from student where 2010-year(csrq)>19 and 2010-year(csrq)<23
1012 select distinct sno from sc where (cno=‘1’ or cno=‘3’) and grade>=75
1013 select * from sc where cno=‘2’ or cno=‘3’ order by cno,grade desc
1014 select sno,grade from sc where cno=‘1’ and grade>70 and sno like ‘%3’ order by grade desc
1015 select * from student where sdept=‘管理系’ and sname not like ‘李%’ and sno like ‘2009%’
1016 select sname,sex,sdept from student where sname like ‘张_’ and sdept=‘信息系’
1017 select sname,sno from student where sname like ‘玲%’ and month(csrq)=4 and day(csrq)=4
1018 select sno,sname from student where sdept=‘信息系’ and sname not like ‘刘%’ and sname like '
_’
1019 select sname,csrq from student where month(**csrq)=8 and day(csrq)=8 and year(csrq)>=1990
1020 select from student where sno like ‘2009%’ and sdept=‘计算机系’ and sex=‘男’ and sname like ‘李%’ and year(csrq)>1985

总结如下:
1.常规语法是select [列名] from [表名] where [限定条件] order by [列名]
2.条件连接词就是and和or
3.模糊查询like:[列名] like ‘’。其中_代表一个字符,%代表所有字符。
4.可以通过year,month,day分别取日期中的年月日。

PS:order by列名默认升序,需要降序可在列名后添加 desc

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值