上午:

(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. lufylegend库 LTextField

    lufylegend库 LTextField <!DOCTYPE html> <html lang="en"> <head> <meta ...

  2. 我的小工具开源一下-PingTest

    v博客前言 先交代下背景,最近我们项目组的网络真是太渣了,时常remote不了另外一个地方的机器,过个几分钟就断开连接,太烦躁了,严重影响工作心情...于是想着做个工具记录下每天的断开remote连接 ...

  3. css3 UI 修饰——回顾

    1.box-shadow 属性向框添加一个或者多个阴影. 语法: box-shadow: h-shadow v-shadow blur spread color inset h-shadow 必须,水 ...

  4. java_JDBC(3)

    Batch和Fetch两个特性非常重要.Batch相当于JDBC的写缓冲,Fetch相当于读缓冲 如果把JDBC类比为JAVA IO的话,不使用Fetch和Batch相当于直接使用FileInputS ...

  5. Webservice_常用

    官网示例: http://cxf.apache.org/docs/writing-a-service-with-spring.html http://cxf.apache.org/docs/jax-r ...

  6. Surface Dial 与 Windows Wheel UWP应用开发

    随着微软发布 Surface Studio 在演示视频中非常抢眼的一个配件就是 Surface Dial,Dial 是Windows输入设备大家庭中的新成员我们把它归类为Windows Wheel 类 ...

  7. java的位运算符

    1.与运算&,同为1为1,否则为0: 例如:10001(二进制)&10000(二进制)=10000(二进制) 2.或运算|,只要有1就是1: 例如:10001(二进制)&100 ...

  8. Java中显示图片的方法

    最近在做一个swing小项目,其中需要把存储在硬盘中的图片文件显示出来,总结了如下方法: 1. Graphics g = getGraphics();String name = "E:/Ca ...

  9. git用法-打补丁

    1. git cherry-pick 作用:从一个branch上选择一个commit,添加该commit到另一个branch上. 1. 切换到你想添加commit的分支上. git checkout ...

  10. 学习笔记——Java数字处理类

    1.数字格式化 使用Java.text.DecimalFormat格式化数字,一般使用其中的DecimalFormat类.如: import java.text.DecimalFormat; publ ...