mysql to second_The second day to learn MySQL

MySQL图形化工具

Navicat

数据操作语言

Create table 表名:  创建表

Insert into 表名(列名1, 列名2, 列名3...)values(列名1值,列名2值, 列名3值.)  :新增值

Delete from 表名  :  删除表

Update 表名 set 列名1=修改的值,列名2=修改的值;    :修改值

Select * from 表名   :查询整个表

Select * from 表名 where 列名1=值 and 列名2=值....     :根据条件查询指定的数据

Select列名1,列名2from      :查询指定的列的数据

Select 列名 (as)别名,列名2 (as)别名2... from 表名;        :给指定返回列取别名(as)表示可有可无

SELECT * FROM 表名 where 字段 > < >= <= !=或<>               :在条件中使用运算符

and or not  (和,或者,不)

ag:select * from student where age<=21 and sex='女' (在表student中查询年龄小于等于21岁的女生)。

ag:select * from student where age<=21 or sex='女' (在表student中查询年龄小于等于21岁的学生或女生) (二者都会被查询出来)。

对空值的查询:is null对应列是否null查询

select * from 表名 where 对应列 is not null

select * from 表名 where 列名 BETWEEN A and B;   查询表中对应列A和B之间的值(包含A和B的值)。

select * from 表名 where 列名 in(a,b,c);  查询表中对应列满足a、b、c中任一一个的值。

模糊查询  like

_:指代明确值的位置或已知字符串长度

%:指代不明确值的位置或长度

select * from 表名 where 列名 like '_A%';  查询表中对应列第二个字为A的值。

select * from 表名 where 列名 like 'A_%';  查询表中对应列第一个字为A的值。

select * from 表名 where 列名 like '%A%';  查询表中对应列含有A的值。

查询中使用算术表达式:+ - * /  :在表中对相应列进行运算。

处理重复值:DISTINCT排除重复展示,只展示一次

select DISTINCT sex from 表名;      只展示一次表中的性别。

select * from 表名 limit 10;查询数据的前10位

select * from 表名 limit 10,10;    查询表中第11至第20位的数据 (有多少数据显示多少数据,直到第20个)

create table 目标表名 select*from 现有表名;   把现有表复制到目标表中。

create table 目标表名 select*from where flase;   只复制表的结构。(flase如1=2,当条件不满足时,不复制值)

select * from 表名 order by  :升序排序(默认)

select * from 表名 order by desc   将需拍下

常用函数

得到需要查询字符的ascii码

select ascii('字符');

根据字符集查询得到的字符的长度

select char_length('字符');

拼接字符串

select concat ('字符1','字符2','字符3'......);

大写转小写

select lower('ABC');

小写转大写

select upper('abc');

查询表中对应列的对应数据的最后一个字

select right(对应列,1) from 表名;

查询表中对应列的对应数据的第一个字

select left(对应列,1) from 表名;

聚合函数:

COUNT统计数量:select count(列名) from 表名;

SUM求和:select sum(列名) from 表名;

MAX求最大值:select max(列名) from 表名;

MIN求最小值:select min(列名) from 表名;

AVG平均数:select avg(列名) from 表名;


版权声明:本文为weixin_39682301原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。