上午:

(7)范围查询

select * from car where price>40 and price<60

select * from car where price between 40 and 60

(8)离散查询

select * from car where price=30 or price=40 or price=50 or price=60;

select * from car where price in(30,40,50,60)

select * from car where price not in(30,40,50,60)

(9)聚合函数(统计查询)

select count(*) from car

select count(code) from car #取所有的数据条数

select sum(price) from car #求价格总和

select avg(price) from car #求价格的平均值

select max(price) from car #求最大值

select min(price) from car #求最小值

(10)分页查询

select * from car limit 0,10  #分页查询,跳过几条数据(0)取几条(10)

规定一个每页显示的条数:m

当前页数:n

select * from car limit (n-1)*m,m

(11)去重查询

select distinct brand from car

(12)分组查询

查询汽车表中,每个系列下汽车的数量

select brand,count(*) from car group by brand

分组之后,只能查询该列或聚合函数

取该系列价格平均值大于40的系列代号

select brand from car group by brand having avg(price)>40

取该系列油耗最大值大于8的系列代号

select brand from car group by brand having max(oil)>8

 下午:

高级查询:
1.连接查询
select * from Info,Nation
形成笛卡尔积
select * from Info,Nation where Info.nation=Nation.code

select Info.code,Info.name,Info.sex,Nation.name as '民族',Info.birthday from Info,Nation where Info.nation=Nation.code

select * from Info join Nation on Info.nation=Nation.code

2.联合查询
select code,name from Info
union
select code,name from Nation

3.子查询
子查询查询的结果作为父查询的条件

(1)无关子查询:子查询执行的时候和父查询没有关系
查民族为'汉族'的所有学生信息
select * from Info where nation=(select code from nation where name='汉族')

查询生产厂商为'一汽大众'的所有汽车信息
select * from car where brand=()
select brand_code from brand where prod_code=()
select prod_code from productor where prod_name='一汽大众'

select * from car where brand in(select brand_code from brand where prod_code=(select prod_code from productor where prod_name='一汽大众'))

(2)相关子查询
子查询在执行的时候需要用到父查询的内容

查询汽车表中,汽车油耗小于该系列平均油耗的所有汽车信息

select * from car where oil<(该系列平均油耗)
select avg(oil) from car where brand =(该系列)

select * from car a where oil<(select avg(oil) from car b where b.brand =a.brand)

CRUD操作(20161017)的更多相关文章

  1. 【翻译】MongoDB指南/CRUD操作(四)

    [原文地址]https://docs.mongodb.com/manual/ CRUD操作(四) 1 查询方案(Query Plans) MongoDB 查询优化程序处理查询并且针对给定可利用的索引选 ...

  2. 【翻译】MongoDB指南/CRUD操作(三)

    [原文地址]https://docs.mongodb.com/manual/ CRUD操作(三) 主要内容: 原子性和事务(Atomicity and Transactions),读隔离.一致性和新近 ...

  3. 【翻译】MongoDB指南/CRUD操作(二)

    [原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(二) 主要内容: 更新文档,删除文档,批量写操作,SQL与MongoDB映射图,读隔离(读关 ...

  4. 【翻译】MongoDB指南/CRUD操作(一)

    [原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(一) 主要内容:CRUD操作简介,插入文档,查询文档. CRUD操作包括创建.读取.更新和删 ...

  5. ASP.NET Core Web API Cassandra CRUD 操作

    在本文中,我们将创建一个简单的 Web API 来实现对一个 “todo” 列表的 CRUD 操作,使用 Apache Cassandra 来存储数据,在这里不会创建 UI ,Web API 的测试将 ...

  6. MongoDB的CRUD操作

    1. 前言 在上一篇文章中,我们介绍了MongoDB.现在,我们来看下如何在MongoDB中进行常规的CRUD操作.毕竟,作为一个存储系统,它的基本功能就是对数据进行增删改查操作. MongoDB中的 ...

  7. 【Java EE 学习 44】【Hibernate学习第一天】【Hibernate对单表的CRUD操作】

    一.Hibernate简介 1.hibernate是对jdbc的二次开发 2.jdbc没有缓存机制,但是hibernate有. 3.hibernate的有点和缺点 (1)优点:有缓存,而且是二级缓存: ...

  8. 使用MyBatis对表执行CRUD操作

    一.使用MyBatis对表执行CRUD操作——基于XML的实现 1.定义sql映射xml文件 userMapper.xml文件的内容如下: <?xml version="1.0&quo ...

  9. MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作(转载)

    本文转载自:http://www.cnblogs.com/jpf-java/p/6013540.html 上一篇博文MyBatis学习总结(一)--MyBatis快速入门中我们讲了如何使用Mybati ...

  10. MyBatis入门学习教程-使用MyBatis对表执行CRUD操作

    上一篇MyBatis学习总结(一)--MyBatis快速入门中我们讲了如何使用Mybatis查询users表中的数据,算是对MyBatis有一个初步的入门了,今天讲解一下如何使用MyBatis对use ...

随机推荐

  1. 对angularjs时间过滤格式

    在最近的项目中,我遇到这样的一个小问题,从后台传过来一个时间值,格式如下: "/Date(1484743002000)/" 至于为什么是这种格式,后台的开发说数据库中就是这个存的( ...

  2. HDU3790

    最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  3. A tutorial on Principal Components Analysis | 主成分分析(PCA)教程

    A tutorial on Principal Components Analysis 原著:Lindsay I Smith, A tutorial on Principal Components A ...

  4. Wireshark网络抓包(一)——数据包、着色规则和提示

    一.数据包详细信息 Packet Details面板内容如下,主要用于分析封包的详细信息. 帧:物理层.链路层 包:网络层 段:传输层.应用层 1)Frame 物理层数据帧概况 2)Ethernet ...

  5. 一个案例深入Python中的__new__和__init__

    准备 在Python中,一切皆对象. 既然一切皆对象,那么类也是对象,我们暂且称之为 类对象.来个简单例子(本篇文章的所有案例都是运行在Python3.4中): class foo(): pass p ...

  6. 《JAVASCRIPT高级程序设计》事件处理程序和事件类型

    一.事件流 谈到事件,首要要理解事件流的概念:事件流是指从页面接受事件的顺序:“DOM2级事件”规定事件流包括三个阶段:事件捕获阶段.处于目标阶段和事件冒泡阶段.目前大部分的浏览器的事件流是事件冒泡, ...

  7. oracle 12c安装详细教程

    数据库下载:www.orcale.com访问官网自行下载. 一,将下载好的两个压缩包在同一目录中进行解压(文件目录尽量用英文) 解压后如下使用管理员身份运行setup安装程序 注意:对于学习阶段,这一 ...

  8. 点击弹窗后再刷新html页面

    当alert弹出框点击确定以后,再让页面重新加载一下 具体的代码如下: <script type="text/javascript"> alert("签到成功 ...

  9. Masonry的简单使用

    #import "RootViewController.h" #import "Masonry.h" @interface RootViewController ...

  10. final对于访问效率的影响

    在能够通过编译的前提下,无论局部变量声明时带不带final关键字修饰,对其访问的效率都一样. 并且:重复访问一个局部变量比重复访问一个成员或静态变量快:即便将其final修饰符去掉,效果也一样. 例如 ...