欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

数据库11:运算符

程序员文章站 2022-05-10 07:57:22
...

数据库

十一、运算符

算术运算符

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)
*/

比较运算符

数据库11:运算符

  • 常规比较
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)
*/
  • Null 比较
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)
*/
  • 模糊比较: like
select 'HelloWorld' like 'hello%';
/* 输出
+----------------------------+
| 'HelloWorld' like 'hello%' |
+----------------------------+
|                         1 |
+----------------------------+
1 row in set (0.00 sec)
*/

逻辑运算符

数据库11:运算符

相关标签: 基础 数据库