运算符操作

1、数值比较/字符比较
  1、数值比较 := != > >= < <=
  2、字符比较 := !=

2、逻辑比较
  1、and (两个或多个条件同时成立)
  2、or (任意一个条件成立即可)

3、范围内比较
  1、where 字段名 between 值1 and 值2
  2、where 字段名 in(值1,值2,...)
  3、where 字段名 not in(值1,值2,...)

select * from sanguo where ((id in(1,3,4)) and country = "蜀国") or name = "貂蝉";
+------+-----------+--------+--------+------+---------+
| id   | name      | gongji | fangyu | sex  | country |
+------+-----------+--------+--------+------+---------+
|    1 | 诸葛亮    |    120 |     20 | 男   | 蜀国    |
|    3 | 关羽      |    188 |     60 | 男   | 蜀国    |
|    6 | 貂蝉      |    666 |     10 | 女   | 魏国    |
+------+-----------+--------+--------+------+---------+

 

4、匹配空、非空
  1、空 :where name is null
  2、非空:where name is not null
  3、注意
    1、NULL :空值,只能用 is 或者 is not 去匹配
    2、"" :空字符串,用 = 或者 != 去匹配

5、模糊比较
  1、where 字段名 like 表达式
  2、表达式
    1、_ : 匹配单个字符
    2、% : 匹配0到多个字符
      ## NULL不会被统计,只能用is、is not去匹配

posted on 2018-08-30 22:20  zengsf  阅读(112)  评论(0编辑  收藏  举报

导航