MySQL database operations 5-common operators

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise bitwise operators logical operators

Overview:

Common operators include:

Arithmetic operators,

comparison operators,

logical operators,

Bitwise manipulation Operators

etc...

1. Arithmetic operators:

Supports +–*/and%,

For example, when looking for data, use:

Select n+1, n+2 from Num;

Before:, after:

You can also use other operations.

Note that the Division will take four digits after the decimal point. The result of the addition of 0 is meaningless null.

2. Comparison operators

The comparison operator returns a result that is typically 9, 1, or null, which can be used in query statements to query for records that satisfy a condition.

Common comparison operators are described in:

=

Select 1=0,2=2,'1'=1,1+2=3+0,NULL=NULL;

The result is:

Because = is not used for null judgments, the last result is null and cannot be judged.

Same usage, not equal to <> or! =, less than or equal to <=, less than <, greater than or equal to >=, greater than; Note These operators can also compare strings and compare them in the order in which they are arranged.

Is null, ISNULL (), or is not NULL

Determines whether a value is empty.

Such as:

Select NULL  is null,isnull(nullis notnull;

The result is:

Between and

Determine if there is a range, such as

Select 4 between 3  and ten;

Results:

Note String types are range-compared in the order of the character descriptor.

Such as:

Select ' F ' between ' a '  and ' g ';

Results:

LEAST (value 1, value 2, ...)

Returns the minimum value, but returns null if there is null in the value, such as:

Select Least (ten,3.0,+), least (4);

The result is:

When comparing strings, it is also the smallest string to be compared, such as:

Select least ('abc','abd',' ABCD ');

Results:

Greatest

In contrast to least, the maximum value is compared. Such as:

Select Greatest ('abc','abd','ABCD  ');

The result is:

In,not in

Determine if the value is in the list, such as:

Select 4 inch(1,4,'R','T'),'R'  not inch(1,4,'R','T');

The result is:

Null is returned when the left side is null or if no match is found and there is null in the list.

Like

Pseudo-Regular match, only supports the two wildcard characters% and _,% means match any number of characters, _ matches any single character.

Such as:

Select ' Student '  like ' st% ';

The result is:

As you can see, the string following the like is a regular expression, preceded by a string to be matched.

Regexp

The regular expression matches, ^ matches the beginning, the $ matches the end,. Match single character, [] match the characters in it (supported with-specified range), * match its preceding characters any number of times (I disagree when using *, because there may be problems when using *).

Such as:

Select ' Ssky ' ' [AB] ','Ssky's*';

The result is:

If by definition, the s* match does not match the KY, but the result is a return to True (1). Please advise me if you have any knowledge.

3. Logical Operators

Not OR!

When the operand is 1 at 0 and 0 is 1, the inverse is taken, such as:

Select  not (1),not0 ,! True

The result is:

And OR &&

and operation;

Such as:

Select 1  and 1,0and1;

Results:

OR OR | |

or operation;

Such as:

Select 1 or 1,0| | 1;

Results:

Xor

(The same is 0, the difference is 1)

Such as:

Select 0 0;

Results:

4. Bitwise operators (slightly).

Because bit operations are mainly used with binary, the occasion is special, so I do not remember for the time being, but the MySQL-supported bitwise operators have

| Bit or

& Bit and

^ Bit XOR or

<< left-shift

>> bit Right Shift

-To-take counter

MySQL database operations 5-common operators

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.