简单查询
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 查询的更多相关文章

  1. SQL 必知必会·笔记<12>组合查询

    什么是组合查询 SQL 通过执行多个查询(多条SELECT 语句),并将结果作为一个查询结果集返回.这些组合查询通常称为并(union)或复合查询(compound query). 什么时候使用组合查 ...

  2. MongoDB(12)- 查询嵌入文档的数组

    插入测试数据 db.inventory.insertMany( [ { item: "journal", instock: [ { warehouse: "A" ...

  3. jdbc 12: 模糊查询

    jdbc连接mysql,进行模糊查询 package com.examples.jdbc.o11_模糊查询; import com.examples.jdbc.utils.DBUtils; impor ...

  4. 12 Mapping查询

    查看 某个index下所有type的mapping GET /beauties/_mapping 查看 指定index.指定type的mapping GET /beauties/_mapping/cn

  5. mysql语句查询练习

                                                                     1.创建students表mysql> create table ...

  6. 转载:MySQL 语句大全:创建、授权、查询、修改等

    本文转载>这里 一.用户创建.权限.删除 1.连接MySql操作 连接:mysql -h 主机地址 -u 用户名 -p 用户密码 (注:u与root可以不用加空格,其它也一样)断开:exit ( ...

  7. Drools 查询学习

    Drools 查询学习查询以 query 关键字开始,以 end 关键字结束,在 package 当中一个查询要有唯一的名称,查询的内容就是查询的条件部分,条件部分内容的写法与规则的 LHS 部分写法 ...

  8. TSQL查询45道题

    一.设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher). 四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1- ...

  9. Mysql 查询练习

    Mysql 查询练习 ---创建班级表 create table class( cid int auto_increment primary key, caption ) )engine=innodb ...

  10. SQL查询语句 常用示例

    SQL语言的应用 1.     找出姓李的读者姓名和所在单位. 2.     列出图书库中所有藏书的书名及出版单位. 3.     查找高等教育出版社的 所有图书及单价,结果按单价降序排序. 4.   ...

随机推荐

  1. android 布局优化常用技巧

    android对多个模块都要是要的UI逻辑的致辞除了fragment之外,没有别的东西可以支持了, include,merge,viewstub只能支持公用的ui,但是这个通用支持不能包含逻辑(jav ...

  2. lambda的使用ret = filter(lambda x : x > 22 ,[11,22,33,44])

    #!/usr/bin/env python #def f1(x) : # return x > 22 ret = filter(lambda x : x > 22 ,[11,22,33,4 ...

  3. Beaglebone Black – 智能家居控制系统 LAS - 插座组装

    上一篇完成了服务端,这次是拼图的最后一块,插座. 插座一个,准备废掉它其中一个插头 预想电路草图 物料清单: 两路插座一个 继电器一个,3.3V 能驱动即可: 交流转直流 3.3V,我买了现成的模块: ...

  4. centos使用yum安装mysql

    参考:http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/ 1.增加yum数据源 (1.1)从http://dev.mysql.com/dow ...

  5. Scrum Meeting 5-20151207

    任务安排 姓名 今日任务 明日任务 困难 董元财 将服务器转移到学校服务器 修复app特定情况下崩溃 无 胡亚坤 学习连接服务器框架 发布界面和购买界面 无 刘猛 在github上分配好任务 写博客 ...

  6. java读取配置文件中数据

    Properties pps=new Properties();        try {            pps.load(new FileInputStream("src/emai ...

  7. Security » Authorization » 基于声明的授权

    Claims-Based Authorization¶ 基于声明的授权 142 of 162 people found this helpful When an identity is created ...

  8. Error: listen EADDRINUSE

    有可能是已经作用了18001端口 netstat -antp|grep 18001 kill 然后重启程序. events.js:72 throw er; // Unhandled 'error' e ...

  9. 在centos6.5中安装github的客户端git

    简介 git是一个分布式版本控制软件,我采用的采用的安装方式是源码安装 1.安装编译git时需要的包 # yum install curl-devel expat-devel gettext-deve ...

  10. 饮水思源——python中常用基础类源码解析

    1.bool类 2.int类 3.long类 4.float类 5.str类 6.list类 7.tuple类 8.dict类 9.collections类 Counter类:为hashable对象计 ...