CREATE DATABASE CristinMysql

Create table employee(

eId int(9) not null auto_increment,

eName varchar(8) charset utf8 not null,

eComeDate date not null,

eGender enum('Male','Female','Uncertaion') default null,

primary key (eId)

) engine = InnoDB auto_increment = 20170001 default charset = utf8mb4;

--auto_increment:主键自动增加编号;

--engine = InnoDB 支持事务查询,engine = ISAM 执行读取操作的速度很快,而且不占用大量的内存和存储资源。ISAM的两个主要不足之处在于,它不支持事务处理,也不能够容错;

--utf8与utf8mb4的区别:utf8只支持3个字节,utf8mb4可支持4个字节;

insert into employee values(null,'张三','2015-01-01','Male'),(null,'李四','2015-01-01','Male'),(null,'王五','2014-01-01','Male'),(null,'白凤九','2016-01-01','Male'),(null,'白凤八','2017-01-01','Male'),(null,'张三丰','2015-06-01','Male')

--【简单查询】

select * from employee;

--where【精确查询】

select * from employee where eName = '张';

--like % _【模糊查询,%与_区别:%表示模糊位数,_表示第几位模糊】

select * from employee where eName like '张%';

select * from employee where eName like '张_';

--between and < > <>【区间查询,between and 从哪里到哪里;< > 逻辑区间;<>表示不等于】

select * from employee where eComeDate between 20150101 and 20170101;

select * from employee where eComeDate >= 20160101;

--order by limit【排序规则,默认升序排列,limit表示取几个】

select * from employee where eComeDate >= 20150101 order by eComeDate desc limit 3;

-- and or【和与或】

select * from employee where eComeDate >= 20150101 and eName like '白%';

select * from employee where eComeDate <20150101 or eName like '白%';

-- group by regexp【group by分组查询,regexp选择性查询】

select eGender,count(eId) from employee group by eGender;

select * from employee where eName regexp '张|白';

--【查询函数】

select count(eId) from employee;//集合

select avg(eComeDate) from employee;//平均

select max(eComeDate) from employee;//最大

select min(eComeDate) from employee;//最小

--date【日期查询】

select curdate();-- 获取数据库服务器当前时间

select date_sub(curdate(),interval 1 year);-- DATE_SUB() 函数从日期减去指定的时间间隔,curdate() 参数是合法的日期表达式。interval 1 year 参数是您希望添加的时间间隔。

select * from employee where eComeDate < date_sub(curdate(), interval 1 year);

--disint【不同值】

select distinct(eGender) from employee; --返回唯一不同的值

--【连接查询】

create table company(

id int(3) not null auto_increment,

cName varchar(8) charset utf8mb4 not null,

cEId int (9) not null,

primary key(id)

)engine = InnoDB default charset = utf8;

show tables;

insert into company values (null,'张三','20170001'),(null,'梁宽','20150101'),(null,'白凤九','20170004'),(null,'梁窄','201570001');

select * from company;

 

-- 查询employee 和 company两个表中cEId都有的数据

-- 子查询

select * from company where cEId in (select eId from employee);

-- 连接查询(四种:交叉查询、内查询、左连接、右连接)逻辑:形成一个虚拟表,将多表查询出来之后的连查数据放在里面

-- 交叉查询

select * from company c , employee e where e.eId = c.cEId; -- 隐式的交叉查询,左边表和右边表相同记录的内容,显示出来

select * from company c , employee e where e.eId <> c.cEId; -- 不等于交叉查询,左边表乘以右边表再把相同的记录去掉,然后展示出来

select * from company c cross join employee e where e.eId = c.cEId; -- 隐式的交叉查询,左边表和右边表相同记录的内容,显示出来

-- 【内链接】

select * from company c inner join employee e where e.eId = c.cEId; -- 内链接

select * from company c join employee e where e.eId = c.cEId; -- 默认的内链接

-- 左连接,意义:左表中的数据全部查出来,如果与右表中没有匹配的就用null表示

select * from company c left join employee e on e.eId = c.cEId; -- 写法1

select * from company c left outer join employee e on e.eId = c.cEId; -- 写法2

-- 右连接,意义:右表中的数据全部查出来,如果与左表中没有匹配的就用null表示

select * from company c right join employee e on e.eId = c.cEId;

MySql查询功能梳理的更多相关文章

  1. 复习MySQL④查询功能、连接方式、联合查询

    用select语句查询: select〈目标列组〉 from〈数据源〉 [where〈元组选择条件〉] [group by〈分列组〉[having 〈组选择条件〉]] [order by〈排序列1〉〈 ...

  2. MySQL 5.5开启慢查询功能

    vim /etc/my.cnf [mysqld] slow-query-log = on # 开启慢查询功能 slow_query_log_file = /usr/local/mysql/data/s ...

  3. Vc数据库编程基础MySql数据库的表查询功能

    Vc数据库编程基础MySql数据库的表查询功能 一丶简介 不管是任何数据库.都会有查询功能.而且是很重要的功能.上一讲知识简单的讲解了表的查询所有. 那么这次我们需要掌握的则是. 1.使用select ...

  4. Linux 实例如何开启 MySQL 慢查询功能

    运行 MySQL 时,查询速度比较慢的语句对数据库的影响非常大,这些慢语句大多是写的不够合理或者大数据环境下多表并发查询造成的.MySQL 自带慢查询功能,能记录查询时间超过参数 long_query ...

  5. MySQL 基础知识梳理

    MySQL 的安装方式有多种,但是对于不同场景,会有最适合该场景的 MySQL 安装方式,下面就介绍一下 MySQL 常见的安装方法,包括 rpm 安装,yum 安装,通用二进制安装以及源码编译安装, ...

  6. 创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段

    创建ASP.NET Core MVC应用程序(5)-添加查询功能 & 新字段 添加查询功能 本文将实现通过Name查询用户信息. 首先更新GetAll方法以启用查询: public async ...

  7. MySQL查询缓存

    MySQL查询缓存 用于保存MySQL查询语句返回的完整结果,被命中时,MySQL会立即返回结果,省去解析.优化和执行等阶段. 如何检查缓存? MySQL保存结果于缓存中: 把SELECT语句本身做h ...

  8. MySQL查询执行过程

    MySQL查询执行路径 1. 客户端发送一条查询给服务器: 2. 服务器先会检查查询缓存,如果命中了缓存,则立即返回存储在缓存中的结果.否则进入下一阶段: 3. 服务器端进行SQL解析.预处理,再由优 ...

  9. MySQL查询语句执行过程及性能优化(JOIN/ORDER BY)-图

    http://blog.csdn.net/iefreer/article/details/12622097 MySQL查询语句执行过程及性能优化-查询过程及优化方法(JOIN/ORDER BY) 标签 ...

随机推荐

  1. TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络

    TensorFlow入门,基本介绍,基本概念,计算图,pip安装,helloworld示例,实现简单的神经网络

  2. linux 开始

    3306 -- mysql 8000--django默认 服务由端口控制 https -- 443 http -- 80 linux发行版:1.centos 免费版的redhat2.ubuntu 乌版 ...

  3. 图像处理基础---RGB图 灰度图 索引图 调色板

    (1)二进制图 在二进制图中,像素的取值为两个离散数值0或1中的一个,0代表黑色,1代表白色 例 A=[0 0 1;1 1 0; 0 0 1];>> imshow(A,'InitialMa ...

  4. Codeforces 579A. Raising Bacteria

    You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. ...

  5. 动态创建生成lambd表达式

    基于网上找的一段代码进行修改,目前扩展了NotContains方法的实现 using System; using System.Collections.Generic; using System.Co ...

  6. <转>jmeter(十一)JDBC Request之Query Type

    本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...

  7. MyEclipse 10.7(版本:eclipse 3.7.x-Indigo系列)安装PyDev 4.5.4插件

    解压安装路径结构如截图所示: 安装后重启:

  8. scrapy进阶(CrawlSpider爬虫__爬取整站小说)

    # -*- coding: utf-8 -*- import scrapy,re from scrapy.linkextractors import LinkExtractor from scrapy ...

  9. mysql优化之使用iotop+pt-ioprofile定位具体top io文件

    今天,将一个环境切换成行情优化后的版本后,发现io等待还是挺高,这还是第一次出现的.其他很多套环境都没有这个问题了,故iotop看了下,基本可以确定为是mysql进程的问题,如下: 但是iotop只能 ...

  10. 【Python046--魔法方法:描述符】

    一.描述符的定义: 描述符就是将特殊类型的类的实例指派给另外一个类的属性 1.举例: 特殊类型的类要实现以下三个方法中的其中一个或者全部实现 * __get__(self,instance,owner ...