MySQL Common operators

Source: Internet
Author: User

1. Arithmetic operators
Add
Mysql> 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);

2. Comparison operators
Equals
Mysql> Select 1=0,1=1,null=null;
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;
Inch
Mysql> Select 1 in (N/a), ' t ' in (' t ', ' a ', ' B ', ' l ', ' e '), 0 in ();
Is NULL
Mysql> Select 0 is null,null null;
is not NULL
Mysql> Select 0 is not NULL, and 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 ';

3. Logical operators
Non -
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);
XOR 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);

4. Bitwise operators
Bit and
Mysql> Select 2&3;
Mysql> Select 2&3&4;
Bit or
Mysql> Select 2|3;
Bit XOR or
Mysql> Select 2^3;
Bit-Take counter
Mysql> Select ~1,~18446744073709551614;
Bit right Shift
Mysql> Select 100>>3;
Bit left shift
Mysql> Select 100<<3;

5. Operator Precedence Order
Highest priority: =
1 | |, OR, XOR
2 &&
3 between, case, if, then, ELSE
4 =, <=>, >=, <=, <, <>,! =, is, like, REGEXP, in
5 |
6 &
7 <<, >>
8-, +
9 *,/, DIV,%, MOD
10 ^
One-(unary minus), ~ (unary bit inversion)
It's not.
Lowest-priority BINARY, COLLATE

REF:

Http://www.jb51.net/article/25657.htm

MySQL Common operators

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.