首页 > 数据库 >MySQL比较运算符和函数

MySQL比较运算符和函数

时间:2022-11-07 20:36:08浏览次数:47  
标签:set 函数 22 0.00 运算符 sec MySQL NULL SELECT


本文重点是三个比较运算符

1 ,[NOT[ BETWEEN ...AND...

2  ,  [NOT] IN()

3  ,  IS [NOT] NULL

例1:BETWEEN...AND..

如果数字A在设定范围之内,返回TRUE,否则返回FAUSE

mysql> SELECT 15 BETWEEN 1 AND 22;
+---------------------+
| 15 BETWEEN 1 AND 22 |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.01 sec)


mysql> SELECT 35 BETWEEN 1 AND 22;
+---------------------+
| 35 BETWEEN 1 AND 22 |
+---------------------+
|                   0 |
+---------------------+
1 row in set (0.00 sec)

例2: NOT BETWEEN ...AND...

如果数字A不在设定范围之内,返回TRUE,否则返回FAUSE

mysql> SELECT 35 NOT BETWEEN 1 AND 22;
+-------------------------+
| 35 NOT BETWEEN 1 AND 22 |
+-------------------------+
|                       1 |
+-------------------------+
1 row in set (0.00 sec)

mysql> SELECT 15 NOT BETWEEN 1 AND 22;
+-------------------------+
| 15 NOT BETWEEN 1 AND 22 |
+-------------------------+
|                       0 |
+-------------------------+
1 row in set (0.00 sec)

例3:IN,在列出的几个点之内,返回1,否则为0

mysql> SELECT 10 IN (5,10,22,9);
+-------------------+
| 10 IN (5,10,22,9) |
+-------------------+
|                 1 |
+-------------------+
1 row in set (0.00 sec)

mysql> SELECT 13 IN (5,10,22,9);
+-------------------+
| 13 IN (5,10,22,9) |
+-------------------+
|                 0 |
+-------------------+
1 row in set (0.00 sec)

例4:IN,不在列出的几个点之内,返回1,否则为0

mysql> SELECT 13 NOT IN (5,10,22,9);
+-----------------------+
| 13 NOT IN (5,10,22,9) |
+-----------------------+
|                     1 |
+-----------------------+
1 row in set (0.00 sec)

mysql> SELECT 10 NOT IN (5,10,22,9);
+-----------------------+
| 10 NOT IN (5,10,22,9) |
+-----------------------+
|                     0 |
+-----------------------+
1 row in set (0.00 sec)

例5: IS[NOT] NULL 查找为空的字段

先看一张表

mysql> SELECT * FROM testwish;
+------------+-----------+
| first_name | last_name |
+------------+-----------+
| QQ         | 121       |
| AC         | BD        |
| 121        | 725       |
| tom%       | 2016      |
| NULL       | 11        |
+------------+-----------+
5 rows in set (0.00 sec)

mysql> SELECT * FROM testwish WHERE first_name IS NULL;
+------------+-----------+
| first_name | last_name |
+------------+-----------+
| NULL       | 11        |
+------------+-----------+
1 row in set (0.00 sec)

mysql> SELECT * FROM testwish WHERE first_name IS NOT NULL;
+------------+-----------+
| first_name | last_name |
+------------+-----------+
| QQ         | 121       |
| AC         | BD        |
| 121        | 725       |
| tom%       | 2016      |
+------------+-----------+
4 rows in set (0.00 sec)

补充:

mysql> SELECT NULL IS NULL;
+--------------+
| NULL IS NULL |
+--------------+
|            1 |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT 'NULL' IS NULL;
+----------------+
| 'NULL' IS NULL |
+----------------+
|              0 |
+----------------+
1 row in set (0.00 sec)

mysql> SELECT 0 IS NULL;
+-----------+
| 0 IS NULL |
+-----------+
|         0 |
+-----------+
1 row in set (0.00 sec)



标签:set,函数,22,0.00,运算符,sec,MySQL,NULL,SELECT
From: https://blog.51cto.com/u_11320078/5831318

相关文章

  • MySQL数值运算符和函数
    数值运算符和函数CEIL()         进一取整DIV                 整数除法FLOOR()       舍一取整MOD              ......
  • MySQL自定义函数
    首先,做一个热身。引进一个系统函数LAST_INSERT_ID();这个函数的功能就是放回上一次插入的数据的id做个示范插入数据                       ......
  • MySQL日期时间函数
    日期时间函数NOW()                                           当前日期和时间CURDATE()                ......
  • C++溢出对象虚函数表指针
      C++一特性是通过virtual关键字实现运行时多态,虽然自己用到这个关键字的机会不多,但很多引用的第三方库会大量使用这个关键字,比如MFC...如果某个函数由virtual关键字修......
  • Go | 函数(包)的使用
    实现加减乘除运算传统方法实现:varn1float64=1.2varn2float64=2.1varoptbyte='+'varresfloat64switchopt{case'+':res=n1+n2ca......
  • 函数提高
    3函数提高3.1函数默认参数在C++中,函数的形参列表中的形参是可以有默认值的。语法:返回值类型函数名(参数=默认值){}示例:intfunc(inta,intb=10,intc=10)......
  • MySQL基础篇
    一.MySQL概述(一).什么是数据库?数据库就是存储数据的仓库,简称DB(database);SQL是操作数据库的编程语言,是一套标准,通过编写SQL语句来操作数据库;(二).关系型数据库是将数......
  • mysql 错误:The driver has not received any packets from the server.
    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:CommunicationslinkfailureThelastpacketsentsuccessfullytotheserverwas0millisecondsago.The......
  • W: GPG error: http://repo.mysql.com/apt/ubuntu bionic InRelease: (签名失败)
    签名失败了安装MySQL8.0的时候遇到的问题,当时执行了apt-getupdate的指令,然后出现了下面一大堆Hit:1https://download.docker.com/linux/ubuntubionicInReleaseHit:3htt......
  • DLL的入口点函数
    一、基本介绍系统在不同的时候调用这个入口点函数,这些调用是通知性质的,用来执行一些与进程或者线程有关的清理工作。如果DLL需要这些通知,则需要在源代码中实现这个入口点......