Common mysql operators and usage, mysql Operators

Source: Internet
Author: User
Tags bitwise operators

Common mysql operators and usage, mysql Operators

Mysql has four types of operators:

  • Arithmetic Operators
  • Comparison Operators
  • Logical operators
  • Bitwise operators
  • Arithmetic Operators

Arithmetic Operators are the most basic operation operators in SQL. They mainly include the following operators:

+ (Plus),-(minus), * (multiplication),/(Division), % (remainder or modulo)

Arithmetic Operator test case:

Create Table tmp14, define the field num with the Data Type of INT, insert value 64, perform arithmetic operation on the num value:

First, create table tmp14. The input statement is as follows:

CREATE TABLE tmp14 ( num INT);

Insert data to the field num 64:

INSERT INTO tmp14 value(64);

Next, perform addition and subtraction operations on the num value:

SELECT num, num+10, num-3+5, num+5-3, num+36.5 FROM tmp14;

SELECT num, num * 2, num/2, num/3, num % 3 FROM tmp14;

SELECT 1 = 0, '2' = 2, 2 = 2, '0. 02 '= 0,' B '=' B ', (1 + 3) = (2 + 2), NULL = NULL;

SELECT 'good '<> 'God', 1 <> 2, 4! = 4, 5.5! = 5, (1 + 3 )! = (2 + 1), NULL <> NULL;

SELECT 'good' <= 'God', 1 <= 2, 4 <= 4, 5.5 <= 5, (1 + 3) <= (2 + 1 ), NULL <= NULL;

SELECT 'good' <'God', 1 <2, 4 <4, 5.5 <5, (1 + 3) <(2 + 1), NULL <NULL;

SELECT 'good '> = 'God', 1> = 2, 4> = 4, 5.5> = 5, (1 + 3)> = (2 + 1 ), NULL> = NULL;

SELECT 'good '> 'God', 1> 2, 4> 4, 5.5> 5, (1 + 3)> (2 + 1), NULL> NULL;

Select null is null, ISNULL (NULL), ISNULL (10), 10 is not null;

SELECT 4 BETWEEN 4 AND 6, 4 BETWEEN 4 AND 6, 12 BETWEEN 9 AND 10;

SELECT 'x' BETWEEN 'F' AND 'G', 'B' BETWEEN 'A' AND 'C ';

SELECT least (20.0), least (3.0, 100.5,), least ('A', 'C', 'B'), least (10, NULL );

SELECT greatest (20.0), greatest (3.0, 100.5,), greatest ('A', 'C', 'B'), greatest (10, NULL );

SELECT 2 IN (1, 3, 5, 'thk'), 'thk' IN (1, 3, 5, 'thk ');

Select null in (1, 3, 5, 'thk'), 10 IN (1, 3, NULL, 'thk ');

SELECT 'stud' LIKE 'stud', 'stud' LIKE 'stu _ ', 'stud' LIKE' % d', 'stud' LIKE't ___','s like null;

SELECT 'ssky 'regexp' ^ s', 'ssky 'regexp' y $ ', 'ssky 'regexp'. sky', 'ssky 'regexp' [AB]';

Select not 10, NOT (1-1), NOT-5, not null, NOT 1 + 1;

SELECT! 10 ,! (1-1 ),! -5 ,! NULL ,! 1 + 1;

SELECT 1 AND-1, 1, 1, and null, 0 and null;

SELECT 1 &-& NULL, 0 & NULL;

SELECT 1 OR-1 OR 0, 1 OR 2, 1 or null, 0 or null, null or null;

SELECT 1 |-1 | 0, 1 | 2, 1 | NULL, 0 | NULL, NULL | NULL;

SELECT 1 XOR 1, 0 XOR 0, 1 XOR 0, 1 xor null, 1 XOR 1 XOR 1;

Run the preceding statement and the result is as follows.

SELECT 10 | 15, 9 | 4 | 2;

SELECT 10 & 15, 9 & 4 & 2;

SELECT 10 ^ 15, 1 ^ 0, 1 ^ 1;

SELECT 1 <2, 4 <2;

SELECT 1> 1, 16> 2;

SELECT 5 &~ 1;

Operator priority

  • The priority of an operation determines the order in which different operators are computed in an expression.
  • High-level operators are computed first. If the level is the same, MySQL is calculated from left to right in the order of expressions. Of course, when the priority cannot be determined, you can use parentheses () to change the priority.

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.