12-4mysql 查询
简单查询
select * from 表名; 注意:*代表所有
);
查询指定列
select 列名,列名 from 表名
修改结果集的列名
select 列名 as'',列名 as'' from 表名
条件查询
select * from 表名 where 条件
多条件查询
select * from 表名 where 条件 or 条件
select * from 表名 where 条件 and 条件
范围查询
select * from 表名 where price>=40 and price<=60;
select * from 表名 where price betwen 60 and 80
离散查询
select * from 表名 where price in(20,30,40,50);
select * from 表名 where price not in(20,30,40,50)
模糊查询(关键字查询)
select * from 表名 where name like '%奥迪%' %代表任意多个字符
select * from 表名 where name like '_马%' _代表任意一个字符
9.排序查询
select * from car order by price asc asc升序(省略)
select * from car order by oil desc desc降序
先按照brand升序排,再按照price降序排
select * from car order by brand,price desc
去重查询
select distinct 列 from 表名
分页查询
一页显示10条,当前是第二页
select *from 表名 limit 10(跳过多少条),10(取第三条)
聚合函数(统计函数)
select count (主键) from 表名 查询数据总条数
select sum (列名) from 表名 求和
select avg(列名) from 表名 求平均
select max(列名) from 表名 求最大值
select min (列名) from 表名 求最小值
分组查询
查询汽车表中每个系列下有多少个汽车
select brand,count (*) from car group by brand
查询汽车表中所买的数量大于3的系列
select brand from car group by brand having count(*)>3
高级查询
1.连接查询,对结果集列的扩展
select *from 表1, 表2 #形成笛卡尔积
select *from 表1, 表2 where 表1.列=表2.列
select *from 表1join 表2 on 表1.列=表2.列
联合查询,对结果集行的扩张
select 列 from 表1
union
select 列 from 表2
子查询(里层查询)
父查询(外层查询)
子查询的结果作为父查询的条件
(1)无关子查询
子查询在执行时候和父查询没关系,子查询可以单独查询
1.查询民族为汉族的所有人员信息
父查询:select * from info where nation=()
子查询:select code from nation where name='汉族'
select * from info where nation=(select code from nation where name='汉族')
(2)相关子查询
子查询在执行时候和父查询有关系,子查询不可以单独查询
查询汽车表中油耗小于该系列平均油耗的汽车信息
父查询select *from car where oil<(该系列平均油耗)
子查询 select avg (oil) from car where brand=该系列
select *from car as a where oil<(select avg (oil) from car as b where b.brand=a.brand)
12-4mysql 查询的更多相关文章
- SQL 必知必会·笔记<12>组合查询
什么是组合查询 SQL 通过执行多个查询(多条SELECT 语句),并将结果作为一个查询结果集返回.这些组合查询通常称为并(union)或复合查询(compound query). 什么时候使用组合查 ...
- MongoDB(12)- 查询嵌入文档的数组
插入测试数据 db.inventory.insertMany( [ { item: "journal", instock: [ { warehouse: "A" ...
- jdbc 12: 模糊查询
jdbc连接mysql,进行模糊查询 package com.examples.jdbc.o11_模糊查询; import com.examples.jdbc.utils.DBUtils; impor ...
- 12 Mapping查询
查看 某个index下所有type的mapping GET /beauties/_mapping 查看 指定index.指定type的mapping GET /beauties/_mapping/cn
- mysql语句查询练习
1.创建students表mysql> create table ...
- 转载:MySQL 语句大全:创建、授权、查询、修改等
本文转载>这里 一.用户创建.权限.删除 1.连接MySql操作 连接:mysql -h 主机地址 -u 用户名 -p 用户密码 (注:u与root可以不用加空格,其它也一样)断开:exit ( ...
- Drools 查询学习
Drools 查询学习查询以 query 关键字开始,以 end 关键字结束,在 package 当中一个查询要有唯一的名称,查询的内容就是查询的条件部分,条件部分内容的写法与规则的 LHS 部分写法 ...
- TSQL查询45道题
一.设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1- ...
- Mysql 查询练习
Mysql 查询练习 ---创建班级表 create table class( cid int auto_increment primary key, caption ) )engine=innodb ...
- SQL查询语句 常用示例
SQL语言的应用 1. 找出姓李的读者姓名和所在单位. 2. 列出图书库中所有藏书的书名及出版单位. 3. 查找高等教育出版社的 所有图书及单价,结果按单价降序排序. 4. ...
随机推荐
- cas的http配置和rmi远程调用
1.cas配置http请求(服务端) 1) 解压cas-server-3.4.4-release.zip将modules目录下的cas-server-webapp-3.4.4.war改名称为cas.w ...
- Apache Solr 访问权限控制
Current state of affairs SSL support was added in version 4.2 (SolrCloud v4.7). Protection of Zookee ...
- 剑指offer一:二维数组中的查找
题目: 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 思路: 这是一个顺序二维 ...
- js处理iframe中子页面与父页面里面对象的取得的解决方案
[1]子页面取得父页面的dom对象 parent.window.$('#id').val(""); [2]父页面取得子页面的对象 $(window.frames[&qu ...
- ThinkPHP 3.2 模板中的Angularjs 的变量{{$first}} 无法被解析
ThinkPHP 3.2 模板中的Angularjs 的变量"{{$first}}" 无法被解析, 模板解析冲突,例如在angularjs 的变量"{{$first}}& ...
- suds调用webservice
一.安装 pip install suds 二.日志 import logging logging.basicConfig(level=logging.INFO) logging.getLogger( ...
- idea 工程添加svn关联
1.想启用idea的SVN插件还需要在idea配置一下(Ctrl + Alt + S),如下图所示: 2.接下来启用idea的版本控制插件(这里当然是启用Subversion了),打开“VCS”菜单项 ...
- 用友华表Cell一些用法小结(cs.net版本)
//从Color类型得到RGB类型,也可以用ColorTranslator.ToOle()方法 public int GetRGBFromColor(Color color) { byte r = c ...
- JQuery_简单选择器
jQuery 最核心的组成部分就是:选择器引擎.它继承了 CSS 的语法,可以对 DOM 元素的标签名.属性名.状态等进行快速准确的选择,并且不必担心浏览器的兼容性. jQuery选择器实现了 CSS ...
- mybatis 模糊查询 like
1. 参数中直接加入%% param.setUsername("%CD%"); param.setPassword("%11%"); <sel ...