The second day to learn MySQL

      MySQL图形化工具ide

          Navicat 函数

    数据操做语言工具

        Create table 表名:  建立表spa

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

          Delete from 表名  :  删除表排序

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

       Select * from 表名   :查询整个表字符串

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

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

     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 表名;

相关文章
相关标签/搜索