MySQL笔记之运算符使用详解


当前第2页 返回上一页


between and和not between and

代码如下:

mysql> select a,a between 15 and 30,a not between 15 and 30 from t1;
+------+---------------------+-------------------------+
| a    | a between 15 and 30 | a not between 15 and 30 |
+------+---------------------+-------------------------+
|   24 |                   1 |                       0 |
+------+---------------------+-------------------------+
 row in set (0.00 sec)

between and 和not between and可以判断数值是否在某一区间内


in
mysql> select a,a in(1,2,23),a in(24,12,22) from t1;
+------+--------------+----------------+
| a    | a in(1,2,23) | a in(24,12,22) |
+------+--------------+----------------+
|   24 |            0 |              1 |
+------+--------------+----------------+
 row in set (0.00 sec)
判断操作数是否在某一集合内


like

代码如下:

mysql> select s,s like 'beijing',s like 'b%g',s like 'bei____',s like '%jing' from t2;
+---------+------------------+--------------+------------------+----------------+
| s       | s like 'beijing' | s like 'b%g' | s like 'bei____' | s like '%jing' |
+---------+------------------+--------------+------------------+----------------+
| beijing |                1 |            1 |                1 |              1 |
+---------+------------------+--------------+------------------+----------------+
 row in set (0.00 sec)

ike可以用来匹配字符串,_代表单个字符,%代表多个字符


逻辑运算符
与运算

代码如下:

mysql> select 2&&2,2&&null,2 and 3,2 and 2;
+------+---------+---------+---------+
| 2&&2 | 2&&null | 2 and 3 | 2 and 2 |
+------+---------+---------+---------+
|    1 |    NULL |       1 |       1 |
+------+---------+---------+---------+
 row in set (0.00 sec)

这里&&和and意思一样


或运算

代码如下:

mysql> select 2||2,2||null,2 or 3,2 or 0;
+------+---------+--------+--------+
| 2||2 | 2||null | 2 or 3 | 2 or 0 |
+------+---------+--------+--------+
|    1 |       1 |      1 |      1 |
+------+---------+--------+--------+
 row in set (0.00 sec)

这里||和or的意思一样


非运算

代码如下:

mysql> select !1,!2,!null;
+----+----+-------+
| !1 | !2 | !null |
+----+----+-------+
|  0 |  0 |  NULL |
+----+----+-------+
 row in set (0.00 sec)

此外还有位运算,目前还没用到,等用到的时候再补上

更多Mysql内容来自木庄网络博客


标签:Mysql

返回前面的内容

相关阅读 >>

mysql如何判断字段是否为null

详细介绍mysql理论和基础知识

mysql修改账号的ip限制条件实例分享

了解mysql中的外键作用

如何将mysql升级到5.7

mysql 5.7中的关键字与保留字详解

mysql的增删改查常用语法

mysql数据类型教程示例详解

mysql无法连接本地地址localhost怎么办

mysql怎么取消外键限制(约束)?

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...