MySQL commonly used examples of operator operations

Source: Internet
Author: User
Keywords Network programming Mysql tutorial
Tags examples mysql mysql tutorial network network programming operations operator operators

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

Arithmetic operators plus
mysql tutorial> select 1 + 2;
Less
mysql> select 2-1;
Multiply
mysql> select 2 * 3;
except
mysql> select 5/3;
Business
mysql> select 5 div 2;
mold
mysql> select 5% 2, mod (5,2);

Logical operators are not
mysql> select not 0, not 1, not null;
mysql> select! 0,! 1,! null;
versus
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);

The comparison operator is equal to
mysql> select 1 = 0,1 = 1, null = null;
not equal to
mysql> select 1 <> 0,1 <> 1, null <> null;
Equal to safety
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 to
mysql> select 'bdf' <= 'b', 'b' <= 'b', 0 <1;
more than the
mysql> select 'a'> 'b', 'abc'> 'a', 1> 0;
greater or equal to
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';


Bitwise operators and
mysql> select 2 & 3;
mysql> select 2 & 3 & 4;
Bit or
mysql> select 2 | 3;
Exclusive OR
mysql> select 2 ^ 3;
Bit reversed
mysql> select ~ 1, ~ 18446744073709551614;
Bit right shift
mysql> select 100 >> 3;
Bit left
mysql> select 100 << 3;

Related Article

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.