MySQL中的运算符使用实例展示
请问,什么是最好的参考文档,我的答案是:真实可行的样例语句。
我一贯秉承着一点:通过自己的双手真实的操作一遍之后的信息是最可靠的,所以在您参考这个小文儿的时候请不要只是“看”,单纯的瞧一瞧是得不到真知滴~~~座右铭:纸上得来终觉浅,绝知此事要躬行!
1.算数运算符
加
mysql> select 1+2;
减
mysql> select 2-1;
乘
mysql> select 2*3;
除
mysql> select 5/3;
商
mysql> SELECT 5 DIV 2;
模
mysql> select 5%2,mod(5,2);
2.比较运算符
等于
mysql> select 1=0,1=1,null=null;
不等于
mysql> select 10,11,nullnull;
安全等于
mysql> select 11,20,00,nullnull;
小于
mysql> select 'a'小于等于
mysql> select 'bdf'大于
mysql> select 'a'>'b','abc'>'a',1>0;
大于等于
mysql> select 'a'>='b','abc'>='a',1>=0,1>=1;
BETWEEN
mysql> select 10 between 10 and 20, 9 between 10 and 20;
IN
mysql> select 1 in (1,2,3), 't' in ('t','a','b','l','e'), 0 in (1,2);
IS NULL
mysql> select 0 is null,null is null;
IS NOT NULL
mysql> select 0 is not null, null is not null;
LIKE
mysql> select 123456 like '123%', 123456 like '%123%', 123456 like '%321%';
REGEXP
mysql> select 'abcdef' regexp 'ab', 'abcdefg' regexp 'k';
3.逻辑运算符
非
mysql> select not 0, not 1, not null;
mysql> select ! 0, ! 1, ! null;
与
mysql> select (1 and 1), (0 and 1), (3 and 1), (1 and null);
mysql> select (1 && 1), (0 && 1), (3 && 1), (1 && null);
或
mysql> select (1 or 0), (0 or 0), (1 or null), (1 or 1), (null or null);
mysql> select (1 || 0), (0 || 0), (1 || null), (1 || 1), (null || null);
异或
mysql> select (1 xor 1), (0 xor 0), (1 xor 0), (0 xor 1), (null xor 1);
mysql> select (1 ^ 1), (0 ^ 0), (1 ^ 0), (0 ^ 1), (null ^ 1);
4.位运算符
位与
mysql> select 2&3;
mysql> select 2&3&4;
位或
mysql> select 2|3;
位异或
mysql> select 2^3;
位取反
mysql> select ~1,~18446744073709551614;
位右移
mysql> select 100>>3;
位左移
mysql> select 100
5.运算符优先级顺序
最高优先级 :=
1 ||, OR, XOR
2 &&, AND
3 BETWEEN, CASE, WHEN, THEN, ELSE
4 =, , >=, >, , !=, IS, LIKE, REGEXP, IN
5 |
6 &
7 >
8 -, +
9 *, /, DIV, %, MOD
10 ^
11 - (unary minus), ~ (unary bit inversion)
12 !, NOT
最低优先级 BINARY, COLLATE
好运。
-- The End --

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In the C language, there is no root operator. The built-in function "sqrt()" is used to open the root, and the syntax "sqrt(value x)" is used; for example, "sqrt(4)" is to perform the square root operation on 4. , the result is 2. sqrt() is a built-in root operation function in C language. Its operation result is the arithmetic square root of the function variable; this function can neither operate negative values nor output imaginary results.

In Java, "%" means remainder. It is a binary arithmetic operator that can perform division operations and obtain the remainder. The syntax is "operand 1 % operand 2". The operand of the remainder operator "%" is usually a positive integer or a negative number or even a floating point number. If a negative number participates in this operation, the result depends on whether the previous number is positive or negative.

For Golang developers, "invaliduseof...operator" is a common error. This error usually occurs when using variable-length parameter functions. It will be detected at compile time and indicate which parts have problems. This article will introduce how to solve this error. 1. What is a variable-length parameter function? A variable-length parameter function is also called a variable-parameter function. It is a function type in the Golang language. Using variable-length parameter functions, you can define multiple ones as follows

In PHP, the "==" symbol is a comparison operator that can compare whether two operands are equal. The syntax is "operand 1 == operand 2". The "==" operator compares and tests whether the variable on the left (expression or constant) has the same value as the variable on the right (expression or constant); it only compares the values of the variables, not the data types. If the two values are the same, it returns a true value; if the two values are not the same, it returns a false value.

In PHP, you can use the "%" and "==" operators to determine whether two numbers are divisible; you only need to use the "%" operator to divide the two numbers to get the remainder, and then use the "==" operator Just judge whether the obtained remainder is 0. The syntax is "Number 1 % Number 2 == 0". If it is 0, it can be divisible. If it is not 0, it cannot be divisible.

Python is widely used in a wide range of fields with its simple and easy-to-read syntax. It is crucial to master the basic structure of Python syntax, both to improve programming efficiency and to gain a deep understanding of how the code works. To this end, this article provides a comprehensive mind map detailing various aspects of Python syntax. Variables and Data Types Variables are containers used to store data in Python. The mind map shows common Python data types, including integers, floating point numbers, strings, Boolean values, and lists. Each data type has its own characteristics and operation methods. Operators Operators are used to perform various operations on data types. The mind map covers the different operator types in Python, such as arithmetic operators, ratio

The += operator is used to add the value of the left operand to the value of the right operand and assign the result to the left operand. It is suitable for numeric types and the left operand must be writable.

Magic methods in Python are special methods that allow you to add "magic" to a class. They are often named surrounded by two underscores. Python's magic method, also known as the dunder (double underline) method. Most of the time, we use them for simple things like constructors (init), string representations (str, repr) or arithmetic operators (add/mul). In fact, there are many methods that you may not have heard of but are very useful. In this article, we will sort out these magic methods! We all know the size of the iterator __len__ method, which can be used in container classes Implement the len() function on. However, if you want to get the length of a class object that implements iterator
