Select * from Student
Select * From Course
Select * from SC --子查询 低于总平均成绩的女同学成绩
Select Grade
from Student, SC
Where Student.Sno = SC.Sno and Student.Sex = '女' and
Grade < (Select AVG(Grade) from SC) --(1).把低于总平均成绩的女同学成绩提高5%
Update SC
SET Grade = Grade * (+0.05)
From SC, Student
Where Student.Sno = SC.Sno and Student.Sex = '女' and
SC.Grade < (Select AVG(Grade) from SC) Select * from SC --(2).把SC复制为SC1
--先创建一个表,这里已经复制了,下面那个复制全部数据语句可以省略
Select *
Into SC1
From SC
--复制全部数据
Insert Into SC1
Select * From SC1 --(3)从SC1中删除刘晨所有选课记录
DELETE
FROM SC1
FROM Student
WHERE SC1.Sno = Student.Sno and Student.Sname = '刘晨' Select *
From SC1 --(4).检索每一门课程成绩都大于等于80分的学生学号、姓名和性别,并把检索到的值送往
--另一个已存在的基本表s1(Sno,SNAME,SEX),如果s1不存在,自己创建
--先创建s1
Select * Into s1
FROM Student
--插入数据
INSERT INTO s1(Sno, SNAME, SEX)
Select distinct SC.Sno, Sname, Sex
From SC, Student
Where SC.Sno = Student.Sno and
SC.Sno NOT IN (Select Sno
From SC
Where SC.Grade < ) Select * from SC --(5)创建选课数少于3门的学生的视图SC_3(sno,sname)
Create View SC_3(sno, sname)
AS
Select SC.Sno, Sname
From SC, Student
Group by SC.Sno, Student.Sname, Student.Sno
Having Count(*) < and SC.Sno = Student.Sno --子查询 选课数少于3门的学生
Select SC.Sno, Count(*) as 选课数
From SC
Group by SC.Sno
Having Count(*) < select * From SC_3

--作业二

select * from Student
select * from Course
select * from SC --(1)取出没有选修‘操作系统’课程的学生姓名和年龄
Select distinct SC.Sno, Sname, Sage
From Student, Course, SC
Where Student.Sno = SC.Sno and Course.Cno = SC.Cno
and SC.Sno not in(
select distinct SC.Sno
From Course, SC
where Course.Cno = SC.Cno and Course.Cname = '操作系统') --(2)检索至少选修课程“数据结构”和“C语言”的学生学号。
Select distinct SC.Sno
From Course, SC
where SC.Cno = Course.Cno and Course.Cname in ('数据结构', 'C语言') --(3)检索和“刘晨”同性别并同系的同学的姓名。
select Sname
from Student
Where Sex =
( Select Sex
From Student
Where Sname = '刘晨')
and Sdept =
( Select Sdept
From Student
Where Sname = '刘晨') --(4)求选修课程名为"数据结构"课程的学生的平均年龄;
Select AVG(Sage)
from Student, Course, SC
Where Student.Sno = SC.Sno and Course.Cno = SC.Cno and Course.Cname = '数据结构' --(5)查询没有选课的学生的学号和姓名
Select Sno, Sname
From Student
Where Student.Sno not in
( select distinct SC.Sno
From Student, SC
where Student.Sno = SC.Sno )

SQL语句(十七)综合练习_分组查询_内嵌查询_视图使用的更多相关文章

  1. Sql语句中两个比较迷糊的概念:“连接查询” 与 “外键约束”

    Sql语句中两个比较迷糊的概念:“连接查询” 与 “外键约束 Sql 中的连接查询:就是为了避免笛卡尔积,因为涉及到多表查询的化,不使用连接查询,会先将多个互相乘,求出笛卡尔积,然后在在里面查询符合的 ...

  2. SQL语句汇总(终篇)—— 表联接与联接查询

    既然是最后一篇那就不能只列出些干枯的标准语句,更何况表联接也是SQL中较难的部分,所以此次搭配题目来详细阐述表联接. 上一篇博文说到相关子查询效率低下,那我们怎么能将不同表的信息一起查询出来呢?这就需 ...

  3. java:Hibernate框架3(使用Myeclipse逆向工程生成实体和配置信息,hql语句各种查询(使用hibernate执行原生SQL语句,占位符和命名参数,封装Vo查询多个属性,聚合函数,链接查询,命名查询),Criteria)

    1.使用Myeclipse逆向工程生成实体和配置信息: 步骤1:配置MyEclipse Database Explorer: 步骤2:为项目添加hibernate的依赖: 此处打开后,点击next进入 ...

  4. SQL语句(十二)分组查询

    (十二)分组查询 将数据表中的数据按某种条件分成组,按组显示统计信息 查询各班学生的最大年龄.最小年龄.平均年龄和人数 分组 SELECT <字段名表1> FROM <表名> ...

  5. 2019-1-11 SQL语句汇总——聚合函数、分组、子查询及组合查询

  6. mybatis sql in 查询(mybatis sql语句传入参数是list)mybatis中使用in查询时in怎么接收值

    1.in查询条件是list时 <select id="getMultiMomentsCommentsCounts" resultType="int"> ...

  7. morphia 框架 mongodb内嵌查询

    mongodb中存储的文档格式如下,实现查询fromdata下did和dvid为指定值的数据 { "_id": { "$oid": "553f4a9f ...

  8. mongodb查询返回内嵌符合条件的文档

    db.T_Forum_Thread.find({ "ThreadReply.ReplyContent" : /范甘迪/ }, { "ThreadReply.$" ...

  9. oracle SQL语句练习MERGE、模糊查询、排序、

    Oracle支持的SQL指令可分为数据操作语言语句.数据定义语言语句.事务控制语句.会话控制语句等几种类型:1.数据操作语言语句数据操作语言语句(Data manipulation language, ...

随机推荐

  1. Arduino Leonardo读取DHT22温湿度传感器

    首先在该地址下载库:https://codeload.github.com/nethoncho/Arduino-DHT22/zip/master 使用以下代码测试: /**************** ...

  2. MongoDB安装笔记

    2017年11月17日,在Windows Service 2008R2上成功安装MongoDB. 版本:mongodb-win32-x86_64-2008plus-ssl-3.4.6-signed.m ...

  3. PHP学习心得2

    对于PHP的语法结构,刚开始真的很不习惯,真搞不懂为什么每个变量之前都要加个“$”符号,每个语句写完之后都必须加上“分号”来表示此句已经结束,还有,PHP对字母的大小写是敏感的,写的时候一定要注意大小 ...

  4. WDS迁移注意事项

    先说背景:公司使用WDS来部署操作系统,目前DHCP和WDS都安装在同一台服务器上,但是此服务器已过保,所以筹划迁移,将WDS和DHCP分别迁移到两台服务器上.迁移计划是保持WDS暂时不动,DHCP先 ...

  5. 谁能告诉delphi7 的updatebatch使用属性说明?

    谁能告诉delphi7 的updatebatch使用属性说明? ADODataSet1.UpdateBatch(arAll); 就是提交你的数据集到数据库 arCurrentOnly the upda ...

  6. 字符串(string)与整型(int)、浮点型(float)等之间的转换

    #include <stdlib.h> 1.int/float to string/array: C语言提供了几个标准库函数,可以将任意类型(整型.长整型.浮点型等)的数字转换为字符串,下 ...

  7. tensorflow环境下安装scikit-learn

    1. scikit-learn所依赖的环境: python(>=2.6 or >=3.3) numpy(>=1.6.1) scipy(>=0.9) 可用conda list 查 ...

  8. Visual Studio Code运行Python文件出现 “Linter pylint is not installed ”提示解决办法

    运行Python代码后出现 “Linter pylint is not installed ”提示 只需要添加一行代码就可以解决 { "python.pythonPath": &q ...

  9. BZOJ5092 分割序列(贪心)

    设si为该序列的异或前缀和,则显然相当于求Σmax{sj+sj^si} (i=1~n,j=0~i).从高位到低位考虑,如果该位si为1,无论sj怎么填都是一样的:如果该位si为0,则sj该位应尽量为1 ...

  10. P3455 [POI2007]ZAP-Queries

    题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...