sql语句的30中查询

网址:http://blog.csdn.net/chen782079048/article/details/72828853

设教学数据库Education有三个关系:
学生关系S(SNO,SNAME,AGE,SEX,SDEPT);
学习关系SC(SNO,CNO,GRADE);
课程关系C(CNO,CNAME,CDEPT,TNAME)
查询问题:
1:查所有年龄在20岁以下的学生姓名及年龄。

Select username,age  form student where age<20
2:查考试成绩有不及格的学生的学号

Select   userid from student where成绩<60
3:查所年龄在20至23岁之间的学生姓名、系别及年龄。

Select  username,xibie,age from student where age between 20 and 23
4:查计算机系、数学系、信息系的学生姓名、性别。

Select username,age form student where xi in(‘计算机,数学,信息)
5:查既不是计算机系、数学系、又不是信息系的学生姓名、性别

Select username,age from student where xi is not ‘计算机’ and is not ‘数学’and is not ‘信息’
6:查所有姓“刘”的学生的姓名、学号和性别。

Select username,hao,sex from student where username like‘刘%’
7:查姓“上官”且全名为3个汉字的学生姓名。

Select xing like‘上官_’from student
8:查所有不姓“张”的学生的姓名。

select 姓名 from student where 姓名 not like ‘%’
9:查DB_Design课程的课程号。

Select hao from ke whee kecheng=’DB_Design’
10:查缺考的学生的学号和课程号。

Select hao,kehao form student where缺考
11:查年龄为空值的学生的学号和姓名。

Select hao,username from student where age=’’;
12:查计算机系20岁以下的学生的学号和姓名。

Select hao,username from student where xi=’计算机’ and age<20
13:查计算机系、数学系、信息系的学生姓名、性别。

Select username,sex from student where xi in(计算机系、数学系、信息系)
14:查询选修了C3课程的学生的学号和成绩,其结果按分数的降序排列。

Select hao,chengji from student where ke=’c3’ order by fen desc
15:查询全体学生的情况,查询结果按所在系升序排列,对同一系中的学生按年龄降序排列。

select * from (表名) order by 系号 asc,年龄 desc
16:查询学生总人数。

Select count(id)where student
17:查询选修了课程的学生人数。

Select count(id)where student where ke=’这个课’
18:计算选修了C1课程的学生平均成绩。

select avg(成绩) from table where课程=‘c1
19:查询学习C3课程的学生最高分数。

Select分 where ke=’c3’ order by ke desc limit 1
20:查询各个课程号与相应的选课人数。

select cno ,count(*) as [选课人数]from stu_course group by cno order by [选课人数] desc
21:查询计算机系选修了3门以上课程的学生的学号。

select sno from sc group by sno having count(*)

22:求基本表S中男同学的每一年龄组(超过50人)有多少人?要求查询结果按人数升序排列,人数相同按年龄降序排列。

 

select age, count(*) as [人数] from S      where sex=’男’ group by age having count(*)>50  order by [人数]asc ,age desc
23:查询每个学生及其选修课程的情况。

 

select a.sid from stu a join choice b on a.sid=b.s_id join course c on c.c_id=b.c_id
24:查询选修了C2课程且成绩在90分以上的所有学生。

Select * from ke=c2 and fen >90

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值