【数据库】MySQL中运算符

  • 算术运算符
select 123 + 543, 321 * 5, -456 / 2, 10 % 3, 2 / 0, 3 % 0;
/* 输出:
+-----------+---------+-----------+--------+-------+-------
+
| 123 + 543 | 321 * 5 | -456 / 2 | 10 % 3 | 2 / 0 | 3 % 0
|
+-----------+---------+-----------+--------+-------+-------
+
|       666 |   1605 | -228.0000 |     1 | NULL | NULL
|
+-----------+---------+-----------+--------+-------+-------
+
1 row in set, 2 warnings (0.00 sec)
*/
  • 比较运算符
    在这里插入图片描述
select 1=2, 2<3, 3<=4, 4>5, 5>=3, 8!=9, 8<>9, 'abc' =
'Abc', 'z' > 'a';
/* 输出:
+-----+-----+------+-----+------+------+------+---------
------+-----------+
| 1=2 | 2<3 | 3<=4 | 4>5 | 5>=3 | 8!=9 | 8<>9 | 'abc' =
'Abc' | 'z' > 'a' |
+-----+-----+------+-----+------+------+------+---------
------+-----------+
|   0 |   1 |   1 |   0 |   1 |   1 |   1 |        
    1 |         1 |
+-----+-----+------+-----+------+------+------+---------
------+-----------+
1 row in set (0.00 sec)
*/
select 123 between 100 and 200, 'b' in ('a', 'b', 'c');
/* 输出
+-------------------------+------------------------+
| 123 between 100 and 200 | 'b' in ('a', 'b', 'c') |
+-------------------------+------------------------+
|                       1 |                     1 |
+-------------------------+------------------------+
1 row in set (0.04 sec)
*/
select 12 is null, 23 = null, null = null, null <=>
null, null is null, 32 is not null;
/* 输出
+------------+-----------+-------------+---------------
+--------------+----------------+
| 12 is null | 23 = null | null = null | null <=> null |
null is null | 32 is not null |
+------------+-----------+-------------+---------------
+--------------+----------------+
|         0 |     NULL |       NULL |             1 |
          1 |             1 |
+------------+-----------+-------------+---------------
+--------------+----------------+
1 row in set (0.00 sec)
*/
select 'HelloWorld' like 'hello%';
/* 输出
+----------------------------+
| 'HelloWorld' like 'hello%' |
+----------------------------+
|                         1 |
+----------------------------+
1 row in set (0.00 sec)
*/
  • 逻辑运算符
    在这里插入图片描述
发布了116 篇原创文章 · 获赞 10 · 访问量 1357

猜你喜欢

转载自blog.csdn.net/weixin_44727383/article/details/104979383
今日推荐