MySQL Learning note ten (MySQL operator)

Source: Internet
Author: User

The operator provided by MySQL contains arithmetic operators, comparison operators, logical operators, and bitwise operators.

Arithmetic operators
Includes: +-*/%
1. Get the results after various arithmetic operations
Select
6+4 ' addition ',
6-4 ' subtraction ',
6*4 ' multiplication ',
6/4 ' Division ',
6 Div 4 ' division ',
6%4 ' Find the mold ',
6 mod 4 ' modulo ';
+--+--+--+--–+--+--+--+
| Addition | Subtraction | multiplication | Division | Division | Die-Finding | Die-Finding |
+--+--+--+--–+--+--+--+
| 10 | 2 | 24 | 1.5000 | 1 | 2 | 2 |
+--+--+--+--–+--+--+--+
2, in addition to manipulating values, you can also manipulate the fields in the table
Select Ename ' employee ', Sale ' monthly salary ', sale*12 ' annual salary ' from T_employee;
3, in addition to operators (/and DIV) and modulo operators (% and MoD), if the divisor of 0 will be an illegal operation, the return result is null
Select 6/0 ' Division ',
6 Div 0 ' division ',
6%0 ' Die ',
6MOD0 ' seeking mode ';
+--+--+--+--+
| Division | Division | Die-Finding | Die-Finding |
+--+--+--+--+
| NULL | NULL | NULL | NULL |
+--+--+--+--+
Comparison operators
Comparison operators contain common comparison operators and implement special function comparison operators
Common comparison operators

< = (<=>)! = (<>) >= <=
Attention:
1, = and <=>
* All can be judged by the value, whether the string and the expression are equal, and the equivalent returns 1. otherwise returns 0;
Select
1=1 ' numerical comparison ',
' Cjgong ' = ' cjgong ' string comparison ',
1+2=3+3 ' expression comparison ',
1<=>1 ' numerical comparison ',
' Cjgong ' = ' cjgong ' string comparison ',
1+2<=>3+3 ' expression comparison ';
+ ———-+ —————————— –+ ———— + ———-+ —————————— –+ ———— +
| Numerical comparison | ' Cjgong ' = ' cjgong ' string comparison ' | Expression Comparison | Numerical comparison | ' Cjgong ' = ' cjgong ' string comparison ' | Expression Comparison |
+ ———-+ —————————— –+ ———— + ———-+ —————————— –+ ———— +
| 1 | 0 | 0 | 1 | 0 | 0 |
+ ———-+ —————————— –+ ———— + ———-+ —————————— –+ ———— +
* When comparing strings for equality, = cannot manipulate null, while the latter can.
mysql> Select Null<=>null ' <=> symbol effect ', null=null ' = symbol effect ';
+ ————-+ ——— –+
| <=> Symbolic Effects | = Symbol Effect |
+ ————-+ ——— –+
| 1 | NULL |
+ ————-+ ——— –+
2,! = and <> These two comparison operators cannot manipulate null
3. >,>=,<,<= comparison operators also cannot manipulate null
Special operators
Between...and
Is null
Inch
Like
RegExp: Regular expression matching
Regular expressions
The mode characters supported by MySQL are as follows:
^ Start
$ end
. Any one character
Any one of the characters in the [character set] Collection
Any character outside the collection of [^ charset]
STR1|STR2|STR3 matches any one of three strings
* Match characters, 0 or 1
+ Match character, contains 1
string {n} string appears N times
String (m,n) string appears at least M times, up to N times
logical operators
and (&&)
OR (| |)
Not (!)
Xor
Bitwise operators
& | ~ ^ << >>
BIN () binary representation
Select 4&5,bin (4&5) ' binary ', 4&5&6,bin (4&5&6) ' binary ';
+-–+--–+ ——-+--–+
| 4&5 | binary | 4&5&6 | binary |
+-–+--–+ ——-+--–+
| 4 | 100 | 4 | 100 |
+-–+--–+ ——-+--–+

MySQL Learning note ten (MySQL operator)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.