", "<> (!=)", "<=", ">=", >, "IS NULL", "IS NOT NULL", LEAST, GREATEST, IN , ""NOT IN", LIKE, REGEXP, etc."/> ", "<> (!=)", "<=", ">=", >, "IS NULL", "IS NOT NULL", LEAST, GREATEST, IN , ""NOT IN", LIKE, REGEXP, etc.">

Home >Database >Mysql Tutorial >What are the comparison operators?

What are the comparison operators?

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-12 14:46:1421889browse

Comparison operators include: =, "", " (!=)", "=", >, "IS NULL ”, “IS NOT NULL”, LEAST, GREATEST, IN, “”NOT IN”, LIKE, REGEXP, etc.

What are the comparison operators?

this Tutorial operating environment: windows7 system, mysql8 version, Dell G3 computer.

Comparison operators can be used to compare numbers and strings. Today I will post a detailed explanation of Mysql comparison operators, I hope it will be helpful to beginners, although NoSQL is popular now, but MYSQL is still very useful. Numbers are compared as floating point values, strings are compared with differences as an example, and the = operator is used to compare whether both sides of an expression are equal. You can also compare strings.

Operators are used to test whether both sides of an expression are not equal and return a true value if they are not equal.

You can also compare strings.

Comparison operators

The result of a comparison operator is always 1, 0 or NULL. The comparison operators in MySQL are:

=, , (!=) , =, >, IS NULL, IS NOT NULL, LEAST, GREATEST, BETWEEN . . . AND. . . , ISNULL, IN, NOT IN, LIKE, REGEXP

Use' =' To judge equality, the SQL statement is as follows:

SELECT 1=0, &#39;2&#39;=2, 2=2,&#39;0.02&#39;=0, &#39;b&#39;=&#39;b&#39;, (1+3) = (2+2),NULL=NULL;

What are the comparison operators?

Use '' to judge equality, the SQL statement is as follows:

What are the comparison operators?

As you can see from the results, '' has a similar effect to '=' when performing comparison operations. The only difference is that '' can be used Judge NULL, and the return value is 1 when both are NULL.

Not equal to operator or !=

''or'!=' Used to judge whether numbers, strings, or expressions are not equal. If they are not equal, the return value is 1; otherwise, the return value is 0. These two operators cannot be used to judge the empty value NULL.

Use '' and '!=' are used to judge inequality. The SQL statement is as follows:

SELECT &#39;good&#39;<>&#39;god&#39;, 1<>2, 4!=4, 5.5!=5, (1+3)!=(2+1),NULL<>NULL;

What are the comparison operators?

It can be seen from the results that the two inequality operators work Same, you can compare numbers, strings, and expressions.

Use '

SELECT &#39;good&#39;<=&#39;god&#39;, 1<=2, 4<=4, 5.5<=5, (1+3) <= (2+1),NULL<=NULL;

What are the comparison operators?

As you can see from the results, when the left operand is less than or equal to the right, the return value is 1, for example: 4

Use '

SELECT &#39;good&#39;<&#39;god&#39;, 1<2, 4<4, 5.5<5, (1+3) < (2+1),NULL<NULL;

What are the comparison operators?

Use '>=' for comparison and judgment, the SQL statement is as follows:

SELECT &#39;good&#39;>=&#39;god&#39;, 1>=2, 4>=4, 5.5>=5, (1+3) >= (2+1),NULL>=NULL;

What are the comparison operators?

Use '>' for comparison and judgment. The SQL statement is as follows:

SELECT &#39;good&#39;>&#39;god&#39;, 1>2, 4>4, 5.5>5, (1+3) > (2+1),NULL>NULL;

What are the comparison operators?

Use IS NULL, ISNULL and IS NOT NULL determines NULL values ​​and non-NULL values. The SQL statement is as follows:

SELECT NULL IS NULL, ISNULL(NULL),ISNULL(10), 10 IS NOT NULL;

What are the comparison operators?

Use BETWEEN AND to judge the value range. Enter the SQL statement as follows:

SELECT 4 BETWEEN 4 AND 6, 4 BETWEEN 4 AND 6,12 BETWEEN 9 AND 10;

What are the comparison operators?

SELECT &#39;x&#39; BETWEEN &#39;f&#39; AND &#39;g&#39;, &#39;b&#39; BETWEEN &#39;a&#39; AND &#39;c&#39;;

What are the comparison operators?

Use the LEAST operator to determine the size. The SQL statement is as follows:

SELECT least(2,0), least(20.0,3.0,100.5), least(&#39;a&#39;,&#39;c&#39;,&#39;b&#39;),least(10,NULL);

What are the comparison operators?

使用GREATEST运算符进行大小判断,SQL语句如下:

SELECT greatest(2,0), greatest(20.0,3.0,100.5), greatest(&#39;a&#39;,&#39;c&#39;,&#39;b&#39;),greatest(10,NULL);

What are the comparison operators?

使用IN、NOT IN运算符进行判断,SQL语句如下:

SELECT 2 IN (1,3,5,&#39;thks&#39;), &#39;thks&#39; IN (1,3,5,&#39;thks&#39;);

What are the comparison operators?

存在NULL值时的IN查询,SQL语句如下:

SELECT NULL IN (1,3,5,&#39;thks&#39;),10 IN (1,3,NULL,&#39;thks&#39;);

What are the comparison operators?

使用运算符LIKE进行字符串匹配运算,SQL语句如下:

SELECT &#39;stud&#39; LIKE &#39;stud&#39;, &#39;stud&#39; LIKE &#39;stu_&#39;,&#39;stud&#39; LIKE &#39;%d&#39;,&#39;stud&#39; LIKE &#39;t_ _ _&#39;, &#39;s&#39; LIKE NULL;

What are the comparison operators?

使用运算符REGEXP进行字符串匹配运算,SQL语句如下:

SELECT &#39;ssky&#39; REGEXP &#39;^s&#39;, &#39;ssky&#39; REGEXP &#39;y$&#39;, &#39;ssky&#39; REGEXP &#39;.sky&#39;, &#39;ssky&#39; REGEXP &#39;[ab]&#39;;

What are the comparison operators?

扩展资料:

逻辑运算符

逻辑运算符的求值所得结果均为TRUE、FALSE或NULL。

逻辑运算符有:

  • NOT 或者 !

  • AND 或者 &&

  • OR 或者 ||

  • XOR(异或)

使用非运算符“NOT”和“!”进行逻辑判断,SQL语句如下:

SELECT NOT 10, NOT (1-1), NOT -5, NOT NULL, NOT 1 + 1;

What are the comparison operators?

SELECT !10, !(1-1), !-5, ! NULL, ! 1 + 1;

What are the comparison operators?

使用与运算符“AND”和“&&”进行逻辑判断,SQL语句如下:

SELECT 1 AND -1,1 AND 0,1 AND NULL, 0 AND NULL;

What are the comparison operators?

SELECT 1 && -1,1 && 0,1 && NULL, 0 && NULL;

What are the comparison operators?

使用或运算符“OR”和“||”进行逻辑判断,SQL语句如下:

SELECT 1 OR -1 OR 0, 1 OR 2,1 OR NULL, 0 OR NULL, NULL OR NULL;

What are the comparison operators?

SELECT 1 || -1 || 0, 1 || 2,1 || NULL, 0 || NULL, NULL || NULL;

What are the comparison operators?

使用异或运算符“XOR”进行逻辑判断,SQL语句如下:

SELECT 1 XOR 1, 0 XOR 0, 1 XOR 0, 1 XOR NULL, 1 XOR 1 XOR 1;

执行上面的语句,结果如下。

What are the comparison operators?

位运算符

位运算符是用来对二进制字节中的位进行测试、移位或者测试处理。位运算符有:

  • 位或(|)

  • 位与(&)

  • 位异或(^ )

  • 位左移(

  • 位右移(

  • 位取反(~)

使用位或运算符进行运算,SQL语句如下:

SELECT 10 | 15, 9 | 4 | 2;

What are the comparison operators?

使用位与运算符进行运算,SQL语句如下:

SELECT 10 & 15, 9 &4& 2;

What are the comparison operators?

使用位异或运算符进行运算,SQL语句如下:

SELECT 10 ^ 15, 1 ^0, 1 ^ 1;

What are the comparison operators?

使用位左移运算符进行运算,SQL语句如下:

SELECT 1<<2, 4<<2;

What are the comparison operators?

使用位右移运算符进行运算,SQL语句如下:

SELECT 1>>1, 16>>2;

What are the comparison operators?

使用位取反运算符进行运算,SQL语句如下:

SELECT 5 & ~1;

What are the comparison operators?


运算符的优先级

  • 运算的优先级决定了不同的运算符在表达式中计算的先后顺序。

  • 级别高的运算符先进行计算,如果级别相同,MySQL按表达式的顺序从左到右依次计算。当然,在无法确定优先级的情况下,可以使用圆括号“()”来改变优先级。

默认情况下,MySQL相关论文,对不区是区分大小写的。如果你需要区分,你需要添加二进制关键字。

=,运算符用于比较表达式的左侧是否小于或等于、大于或等于、小于或大于右侧。

between运算符用于检测某个值是否存在于指定范围内。其中它返回真实值。

您可以添加一个非逻辑运算符来否定between比较,只有当表达式在给定范围之外时,才会返回真值。

in运算符用于验证一个值是否包含在一组指定的值中。其中返回真实值。

为空和非空运算符用于执行包含空值的比较操作

运算符称为空安全等号

相似运算符的通配符。

当使用包含like运算符的查询时,建议确保对where子句中命中的列进行索引,并且where子句包含足够的数据来限制开头搜索的记录数。

相关推荐:《mysql教程

The above is the detailed content of What are the comparison operators?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn