查询语句操作练习题及答案

--查询所有女生的学号、姓名、年龄

select sno,sname,sage
from student
where ssex ='女'

--查询学分小于4的课程号、课程、学分

select cno,cname,ccredit
from course
where ccredit<4

--查询学分在2-4之间(不包括端点)的课程的课程号、课程名和学分

select cno,cname,ccredit
from course
where ccredit>2 and ccredit<4

--查询学分在2-4之间(包括端点)的课程的课程号、课程名和学分

select cno,cname,ccredit
from course
where ccredit between 2 and 4

--查询年龄等于18、19或者20的学生学号、姓名、性别

select  sno,sname,ssex
from student
where sage=18 or sage=19 or sage=20

--查询课程名称以“AB%”结尾的课程的详细情况

select *
from course
where cname like '%AB\%' escape '\'

--查询课程名称中第二个字是“语”的课程的课程号、课程名、学分

select  cno,cname,ccredit
from course
where cname like '_语%'

--查询没有先行课的课程号、课程名

select cno,cname
from course 
where cpno is  null

--查询女生中姓李的学生学号、姓名、所在系

select sno,sname,sdept
from student
where ssex='女' and sname like '李%'

--查询计算机系男生中年龄小于19的学生信息

select * from student where  sdept='CS' and ssex='男' and sage<19

--查询计算机系所有学生的最大年龄、最小年龄和平均年龄

select max(sage),min (sage),avg(sage)
from student
where sdept='CS'

--查询计算机系男生的人数

select count(*)--还可以是count(sno)
from student
where  sdept='CS' and ssex='男'

--查询有选课不及格的学生数

select count(distinct sno)
from sc
where grade<60


--统计选课学生的学号和选课门数,以学号和门数作为结果列名

select sno as 学号,count(cno) as 门数
from sc
group by sno

--统计男生人数和女生人数,以性别和人数作为结果列名

select ssex 性别,count(*) 人数
from student
group by ssex

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值