Use instances to display operators in MySQL

Source: Internet
Author: User
Tags bitwise operators
Excuse me, what is the best reference document? my answer is: a real and feasible sample statement.

Excuse me, what is the best reference document? my answer is: a real and feasible sample statement.

I have always adhered to one point: the information after I perform operations with my hands is the most reliable, so please do not just "read" When you refer to this article ", just looking at it, you can't get any real information ~~~
Motto: The Last Word on the paper. you must know that this is a must!

1. arithmetic operators
Add
Mysql> select 1 + 2;
Subtraction
Mysql> select 2-1;
Multiplication
Mysql> select 2*3;
Division
Mysql & gt; select 5/3;
Vendors
Mysql> SELECT 5 DIV 2;
Module
Mysql> select 5% 2, mod );

2. Comparison operators
Equal
Mysql> select 1 = 0, 1 = 1, null = null;
Not equal
Mysql> select 1 <> 0, 1 <> 1, null <> null;
Security equals
Mysql> select 1 <=> 1, 2 <=> 0 <=> 0, null <=> null;
Less
Mysql> select 'A' <'B', 'A' <'A', 'A' <'A', 'A' <'C', 1 <2;
Less than or equal
Mysql> select 'bdf '<=' B ',' B '<=' B ', 0 <1;
Greater
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 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 '2008080', 123% like '% 100000', 123456 like' % 100000 ';
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 );
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 );

4. bitwise operators
Bitwise AND
Mysql> select 2 & 3;
Mysql> select 2 & 3 & 4;
Bit or
Mysql> select 2 | 3;
Bitwise OR
Mysql> select 2 ^ 3;
Bitwise inversion
Mysql> select ~ 1 ,~ 18446744073709551614;
Shift right
Mysql> select 100> 3;
Shift Left
Mysql> select 100 <3;

5. operator priority order
Highest priority: =
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
Lowest priority BINARY, COLLATE


Good luck.

-- The End --

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.