MySQL查询语句

(1)查询特定的列

    select  列名1,列名2  from 数据表名;

(2)查询所有的列

    select  列名1,列名2,列名3,列名4  from 数据表名;

    select  *  from 数据表名;

(3)给列起别名

    select  列名1 as 别名1,列名2 as 别名2  from 数据表名;

(4)显示不同的记录(相同数据只显示一次)

    Select distinct 列名1 from 数据表名;

(5)查询时执行计算

    select  count(*),列名 from 数据表名 where 列名=‘值1’;(计算列名=‘值1’的数量)

(6)查询的结果集排序

    Select * from 数据表名  order by 列名 asc;  #升序

    Select * from 数据表名  order by 列名 desc; #降序

(7)条件查询

   Select * from 数据表名 where 列名 = '值';

   Select * from 数据表名 where 列名 != '值';

   select * from 数据表名 where 列名 is null;

   select * from 数据表名 where 列名 is not null;

   select * from e数据表名 where 列名1<值 and 列名2=值;

   select * from 数据表名 where 列名 between 值1 and 值2;

   select * from 数据表名 where 列名 not between 值1 and 值2;

   select * from 数据表名 where 列名 in(值1,值2);

   select * from 数据表名 where 列名 not in(值1,值2);

    and / or #和/或

    between .. and .. / not between .. and ..     #在……之间/不在……之间

    in( 值1,值2) / not  in(值1,值2)       #显示值等于'值1,值2'的数据(作用等同于or)

    is null / is not null        #显示空值数据/显示非空数据

(8)模糊条件查询

    select * from 数据表名 where 列名 like '%关键字_';

    %   匹配任意个字符   >=0

    _   匹配任意1个字符   =1

    以上两个匹配的符合必须结合like使用

posted @ 2021-04-06 20:23  chicboy2  阅读(93)  评论(0)    收藏  举报