CRUD操作(20161017)
上午:
(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)的更多相关文章
- 【翻译】MongoDB指南/CRUD操作(四)
[原文地址]https://docs.mongodb.com/manual/ CRUD操作(四) 1 查询方案(Query Plans) MongoDB 查询优化程序处理查询并且针对给定可利用的索引选 ...
- 【翻译】MongoDB指南/CRUD操作(三)
[原文地址]https://docs.mongodb.com/manual/ CRUD操作(三) 主要内容: 原子性和事务(Atomicity and Transactions),读隔离.一致性和新近 ...
- 【翻译】MongoDB指南/CRUD操作(二)
[原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(二) 主要内容: 更新文档,删除文档,批量写操作,SQL与MongoDB映射图,读隔离(读关 ...
- 【翻译】MongoDB指南/CRUD操作(一)
[原文地址]https://docs.mongodb.com/manual/ MongoDB CRUD操作(一) 主要内容:CRUD操作简介,插入文档,查询文档. CRUD操作包括创建.读取.更新和删 ...
- ASP.NET Core Web API Cassandra CRUD 操作
在本文中,我们将创建一个简单的 Web API 来实现对一个 “todo” 列表的 CRUD 操作,使用 Apache Cassandra 来存储数据,在这里不会创建 UI ,Web API 的测试将 ...
- MongoDB的CRUD操作
1. 前言 在上一篇文章中,我们介绍了MongoDB.现在,我们来看下如何在MongoDB中进行常规的CRUD操作.毕竟,作为一个存储系统,它的基本功能就是对数据进行增删改查操作. MongoDB中的 ...
- 【Java EE 学习 44】【Hibernate学习第一天】【Hibernate对单表的CRUD操作】
一.Hibernate简介 1.hibernate是对jdbc的二次开发 2.jdbc没有缓存机制,但是hibernate有. 3.hibernate的有点和缺点 (1)优点:有缓存,而且是二级缓存: ...
- 使用MyBatis对表执行CRUD操作
一.使用MyBatis对表执行CRUD操作——基于XML的实现 1.定义sql映射xml文件 userMapper.xml文件的内容如下: <?xml version="1.0&quo ...
- MyBatis学习总结(二)——使用MyBatis对表执行CRUD操作(转载)
本文转载自:http://www.cnblogs.com/jpf-java/p/6013540.html 上一篇博文MyBatis学习总结(一)--MyBatis快速入门中我们讲了如何使用Mybati ...
- MyBatis入门学习教程-使用MyBatis对表执行CRUD操作
上一篇MyBatis学习总结(一)--MyBatis快速入门中我们讲了如何使用Mybatis查询users表中的数据,算是对MyBatis有一个初步的入门了,今天讲解一下如何使用MyBatis对use ...
随机推荐
- IOS拒绝Adobe的六大理由
苹果与Adobe的关系由来已久.事实上,Adobe的创始人还在他们众所周知的小车库里时,我们就碰过面了.苹果是他们的第一个大客户.我们将他们的Postscript语言应用于当时最新的Laserwrit ...
- 本地ssh连接到vbox中的linux
本机是window xp系统, 安装vbox,在vbox下安装linux,想在xp中用ssh连接linux,此时需要配置网络. 1.设置vbox的网络,选择host-only 2.设置window虚拟 ...
- Backdoor CTF 2013: 电子取证 250
0x00 题目 h4x0r厌烦了你对他的城堡的所有攻击,所以他决定报复攻击你,他给你发来一封带有图片的邮件作为警告,希望你能找出他的警告消息:-) 消息的MD5值就是flag. 0x01 解题法1 给 ...
- WebForm 控件(一)、连接数据库
一.控件 [简单控件] (一)文字显示 1.Label → 在html中相当于span <asp:Label ID="控件名 runat="server" Tex ...
- php类与构造函数解析
关于类大家都有一定的认识这里只介绍在php中类值得注意的地方----类的创建----php使用关键字class创建一个类,并且使用一对大括号如: class name{ public $n=" ...
- SQL SERVER运维日记--收缩数据库
一个小故事 某天,小王正在和HR妹妹闲聊,正HAPPY时,,突然收到系统告警消息,数据库磁盘被剩余空间500M,OMG,不行,磁盘快满了,要是业务要停了,,那就小王只能删库到跑路了,,, 先检查下,有 ...
- 利用matlab进行协方差运算
本文全部参考自: http://www.cnblogs.com/welen/articles/5535042.html#undefined 知识点一: MATLAB中四个取整函数具体使用方法如下:Ma ...
- C语言一维数组复制
/* * 通过自定义的函数memcpy实现复制功能,优点是不需要引用库函数 * 在windows平台下,通过sizeof测试发现: int 4字节 float 4字节 double 8字节 */ #i ...
- 关于github中的README.md文件
0x01 README.md文件是用Markdown语言编写的,md=Markdown; 在线编辑工具: https://stackedit.io/editor# https://maxiang.io ...
- Android开发8:数据存储(二)——SQLite数据库和ContentProvider的使用
前言 啦啦啦各位小伙伴们许久不见了~学期末和过年期间自己忙着做其他事没能及时更新Android开发系列课程的博客,实在是罪过罪过~ 好啦~废话不多说,进入我们今天的主题.今天我们将和大家学习其他的数据 ...