sql大全
来源:互联网 发布:系统重装的软件 编辑:程序博客网 时间:2024/06/05 11:17
小磊有道云笔记http://note.youdao.com/share/?id=909ae89ee779db23034f2514dc92e6c1&type=notebook#/
设教学数据库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
25:查询每个学生选修的课程名及其成绩。
Selct 课程, 成绩from biao1 join biao2 on biao1.id=biao2.tid
26:统计每一年龄选修课程的学生人数。
27:查询选修了C2课程的学生姓名。
28:查询与“张三”在同一个系学习的学生学号、姓名和系别。
29:查询选修课程名为“数据库”的学生学号和姓名。
30:查询与“张三”在同一个系学习的学生学号、姓名和系别。
31:查询选修课程名为“数据库”的学生学号和姓名。
32:查询选修了C2课程的学生姓名。
33:查询所有未选修C2课程的学生姓名。
34:查询与“张三”在同一个系学习的学生学号、姓名和系别。
35:查询选修了全部课程的学生姓名。
36:查询所学课程包含学生S3所学课程的学生学号
//金老师
查所有年龄在20岁以下的学生姓名及年龄
SELECT sname,sage from s where sage <20
查姓“上官”且全名为3个汉字的学生姓名。
SELECT sname from s where sname not like '上官_'
查DB_Design课程的课程号。
#ESCAPE 自定义转义符
SELECT cno,cname from c where cname like 'DB_Design' ESCAPE ''
查缺考的学生的学号和课程号
SELECT sno,cno from sc where grade is null
查询选修了C3课程的学生的学号和成绩,其结果按分数的降序排列。
SELECT sno,grade from sc where cno =1 ORDER BY grade desc
查询全体学生的情况,查询结果按所在系升序排列,对同一系中的学生按年龄降序排列。
SELECT * from s ORDER BY sdept asc ,sage desc
查询选修了课程的学生人数。
SELECT count(DISTINCT(sno)) from sc
查询各个课程号与相应的选课人数。
SELECT COUNT(sno),cno from sc GROUP BY cno
查询计算机系选修了3门以上课程的学生的学号。 HAVING 在结果集中筛选
SELECT s.sno from s,sc where sdept='1502' and s.sno = sc.sno HAVING COUNT(cno)>3
求基本表S中男同学的每一年龄组(超过50人)有多少人?要求查询结果按人数升序排列,人数相同按年龄降序排列。
SELECT COUNT(sage) from s where ssex='男' GROUP BY sage HAVING COUNT(sage)>50 ORDER BY count(sage),sage desc
查询每个学生及其选修课程的情况。
SELECT * from s,sc where s.sno = sc.sno
查询选修了C2课程且成绩在90分以上的所有学生。
SELECT * FROM sc,c where sc.cno = c.cno and grade>80 and cname='php'
查询每个学生选修的课程名及其成绩。
SELECT sname,cname,grade from s,sc,c where sc.cno = c.cno and s.sno = sc.sno
安装文档有没有啊
无言亦懂情i 13:38:26
https://lnmp.org/faq/lnmp-vhost-add-howto.html
无言亦懂情i 13:38:34
这个是配置虚拟主机的
钢蹦儿 13:38:42
恩啦
无言亦懂情i 13:38:45
https://lnmp.org/install.html
查询各科最高成绩:
SELECT MAX(scode) as maxs,xueke from salary GROUP BY xueke;
查询总分前三名:
SELECT sum(scode) as sums,name from salary GROUP BY name ORDER BY sums DESC LIMIT 3
查询平均分前三名:
SELECT avg(scode) as avgs,name from salary GROUP BY name ORDER BY avgs DESC LIMIT 3
查询各科均及格的学生:
SELECT MIN(scode) as mins,name from salary GROUP BY name HAVING mins>=60
- sql大全
- SQL大全
- SQL大全
- SQL大全
- SQL大全
- sql大全
- SQL大全
- SQL大全
- sql大全
- sql大全
- SQL大全
- SQL大全
- SQL大全
- SQL大全
- sql 大全
- sql大全
- SQL 大全
- sql 大全
- 视图helper辅助方法
- python中,包的一般安装位置
- 关于将mac升级到macOS Sierra之后 Sublime Text无法在命令行执行subl .解决办法
- AMS APP进程间通信
- 219Contains Duplicate II
- sql大全
- tuple 元组
- 操作系统总结
- SSM配置 springmvc spring mybatis
- React-Navigation导航(页面跳转)
- playframework Server端接受POST multipart/form-data请求
- 练习45
- 线性表的顺序存储结构
- bootstrap-栅格系统