MySQL Common operator Operation instance

Source: Internet
Author: User
Tags arithmetic operators bitwise

Operator Precedence Order
Highest priority: =
1 | |, OR, XOR
2 &&, and
3 between, case, when, then, else
4 =, <=>, >=, <=, <>,!=, are, like, RegExp, in
5 |
6 &
7 <<, >>
8-, +
9 *,/, Div,%, mod
10 ^
One-(unary minus), ~ (unary bit inversion)
!, not
Lowest priority binary, collate

Arithmetic operators
Add
MySQL tutorials > select 1+2;
Reducing
Mysql> Select 2-1;
By
Mysql> Select 2*3;
Except
Mysql> Select 5/3;
Business
Mysql> Select 5 Div 2;
Mode
Mysql> Select 5%2,mod (5,2);

Logical operator
is not a
Mysql> select not 0, not 1, not null;
Mysql> Select! 0,! 1,! null;
and
Mysql> Select (1 and 1), (0 and 1), (3 and 1), (1 and null);
Mysql> Select (1 && 1), (0 && 1), (3 && 1), (1 && null);
or
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);
Exclusive OR
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);

Comparison operator
equals
mysql> select 1=0,1=1,null=null;
is not equal to
Mysql> select 1<>0,1<>1,null<>null;
Security equals
Mysql> Select 1<=>1,2<=>0,0<=>0,null<=>null;
Less than
mysql> select ' A ' < ' B ', ' A ' < ' a ', ' a ' < ' C ',1<2;
less than or equal
Mysql> select ' BDF ' <= ' B ', ' B ' <= ' B ',0<1;
Greater than
mysql> select ' A ' > ' B ', ' abc ' > ' A ',1>0;
greater than or equal
Mysql> select ' A ' >= ' B ', ' abc ' >= ' A ',1>=0,1>=1;
between
Mysql> Select between 9 between 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 isn't null, NULL is NOT NULL;
Like
mysql> select 123456 like ' 123% ', 123456 like '%123% ', and 123456 like '%321% ';
regexp
mysql> Select ' abcdef ' regexp ' ab ', ' abcdefg ' regexp ' k ';

The


bitwise operator
bit and
Mysql> select 2&3;
Mysql> Select 2&3&4;
bit or
mysql> select 2|3;
Bitwise XOR or
Mysql> select 2^3;
Bit counter
mysql> select ~1,~18446744073709551614;
bit right-shift
Mysql> Select 100>>3;
Bit left
mysql> select 100<<3;

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.