MySQL划重点-查询-条件

  1. 查询的基本语法
  • select * from 表名;

     

  1.  消除重复行
  • 在 select 后面列前使用distinct 可以消除重复的行
  • select distinct gender from students;
    

    一、条件

  • 使用where子句对表中的数据筛选,结果为true的行会出现在结果集中
  • 语法如下
  • select * from 表名 where 条件;
    select * from 表名 where id>2;

    逻辑运算符

  • and
  • or
  • not
  • select * from students where id>3 and gender=o;

    模糊查询

  • like
  • %任意多个字符
  • _任意一个字符
  • select * from students where name like '黄%';

    范围查询

  • in表示在一个非连续的范围内
  • select * from students where id in(1,3,5);

     

  • between...and表示在一个连续的范围内
  • select * from students where id between 3 and 8 and gender=1;

    空判断

  • 注意:null与' '是不同的
  • 判空is null
  • select * from students where hometown is null;
  • 判非空is not null

 

      优先级

  • 小括号,not , 比较运算符,逻辑运算符
  • and比or先运算,如果同时出现并希望先算or,需要结合()使用

 

posted @ 2017-09-19 23:38  zy--  阅读(152)  评论(0编辑  收藏  举报