Reprint Address: http://www.2cto.com/database/201212/175862.html
First, arithmetic operators 1, plus www.2cto.com mysql> Select 1+2; +-----+&N Bsp | 1+2 | +-----+ | 3 | +-----+ 2, minus mysql> Select 1-2; &NBS P +-----+ | 1-2 | +-----+ | -1 | +-----+ 3, multiply mysql> Select 2*3; &NBS P +-----+ | 2*3 | +-----+ | 6 | +-----+ 4, except mysql> Select 2/3; &NBS P +--------+ | 2/3 | +--------+ | 0.6667 | +--------+ 5, Shang www.2cto.COM mysql> Select ten DIV 4; +----------+ &nbs P | DIV 4 | +----------+ | &NBSP;2 | +----------+6, take surplus Mysql> Select 10 MOD 4; +----------+ | MOD 4 | +----------+ | &NBSP;2 | +----------+ II, comparison operator 1, equals mysql> SEL ECT 2=3; +-----+ | 2=3 | +-----+ | 0 | +-----+ mysql> Select NULL = null; +-------------+ | NULL = NULL | +-------------+ | null | +-------------+ 2, not equal to mysql> SEL ECT 2<>3; +------+ | 2<>3 | +------+ | 1 | +------+ 3, security equals and "=" are different when two opcode are null The resulting value is 1 and not null, and when an opcode is null, the resulting value is 0 and not null. mysql> Select 2<=>3; +-------+ | 2<=>3 | +-------+ | 0 | +-------+ mysql> Select null=null; -----------+ | Null=null | +-----------+ | null | +-----------+ &NBSp Mysql> Select null<=>null; +-------------+ | Null<=>null | +-------------+ | 1 | +-------------+ 4, less than mysql> Select 2<3; +-----+ | 2<3 | +-----+ | 1 | +-----+ 5, less than equals mysql> Select 2<=3; &NBS P +------+ | 2<=3 | +------+ | 1 | +------+6, greater than mysql> Select 2>3; -----+ | 2>3 | +-----+ | 0 | +-----+7, greater than equals mysql> Select 2>=3; +------+&NBSP ; | 2>=3 | +------+ | 0 | +------+8, between mysql> Select 5 between 1 and 10; +--------------------+ | 5 between 1 | +--------------------+ | 1 | +--------------------+9, IN&NB Sp Mysql> Select 5 in (1,2,3,4,5); +------------------+ &NBSP ; | 5 in (1,2,3,4,5) | +------------------+ | 1 | +------------------+10, not IN&NBSp Mysql> Select 5 Not IN (1,2,3,4,5); +----------------------+ &nbs P | 5 Not IN (1,2,3,4,5) | +----------------------+ | 0 | +--------------------- -+11, is null mysql> Select NULL is null; +--------------+ & nbsp | NULL is null | +--------------+ | 1 | +--------------+ mysql& Gt Select ' A ' is null; +-------------+ | ' A ' is NULL | +-------------+ | 0 | +-------------+12, is not NUll mysql> Select null is not null; +------------------+ &NB Sp | NULL is NOT NULL | +------------------+ | 0 | +------------------+ &N Bsp mysql> Select ' A ' is not null; +-----------------+ | ' A ' is not NULL | +-----------------+ | 1 | +-----------------+13, like &N Bsp mysql> Select ' 12345 ' like ' 12% '; +--------------------+ | ' 12345 ' like ' 12% ' | +--------------------+ | 1 | &NBsp +--------------------+ mysql> select ' 12345 ' like ' 12_ '; & nbsp +--------------------+ | ' 12345 ' like ' 12_ ' | +--------------------+ | 0 | +--------------------+14, Rege xp mysql> select ' Beijing ' REGEXP ' Jing '; +---------------------- ---+ | ' Beijing ' REGEXP ' Jing ' | +-------------------------+ | 1 | +------------- ------------+ mysql> select ' Beijing ' REGEXP ' XI '; +------------- ----------+ | ' Beijing ' REGEXP ' XI ' | &NBSP; +-----------------------+ | 0 | +-------------------- ---+ three, logical operators www.2cto.com 1, mysql> select 2 and 0; + ---------+ | 2 and 0 | +---------+ | 0 | +---------+ mysql> select 2 and 1; +---------+ | 2 and 1 | +---------+ | 1 | +---------+ 2, or mysql> select 2 or 0;&nbs P +--------+ | 2 or 0 | +--------+ | 1 | &NBSP; +--------+ mysql> select 2 or 1; +--------+ & nbsp; | 2 or 1 | +--------+ | 1 | +--------+ mysql> Select 0 or 0; &n Bsp --------+ | 0 or 0 | +--------+ | 0 | +--------+ mysql> Select 1 | | 0; +--------+ | 1 | | 0 | +--------+ | 1 | +--------+ 3, non- Mysql> Select Not 1; +-------+ | Not 1 | +-------+ | 0 | +-------+ mysql> Select!0; +----+ &NB Sp |!0 | +----+ | 1 | +----+ 4, XOR or www.2cto.com mysql> Select 1 xo R 1; +---------+ | 1 XOR 1 | +---------+ | 0 | +---------+ mysql> Select 0 XOR 0; +---------+ | 0 XOR 0 | +---------+ | 0 | +---------+ mysql> Select 1 xor 0; +---------+ | 1 XOR 0 | +---------+ &NBSP; | 1 | +---------+ mysql> select null or 1;&nbs P +-----------+ | Null or 1 | +-----------+ | 1 | +-----------+ mysql> Select 1 ^ 0 ; +-------+ | 1 ^ 0 | +-------+ | 1 | +-------+ four, bitwise operator 1, bitwise and Mysql> Select 3&5;&nbs P +-----+ | 3&5 | +-----+ | 1 | +-----+ 2, bitwise OR mysql> Select 3|5; &N Bsp +-----+ | 3|5 | +-----+ | 7 | +-----+ 3, Bitwise XOR or mysql> Select 3^5; & nbsp +-----+ | 3^5 | +-----+ | 6 | +-----+ 4, Bitwise counter +----------------------+ &NBSP ; | ~ | +----------------------+&NB Sp | 18446744073709551612 | +----------------------+ Mysql> Select 8446744073709551612; +-----------------------+ | ~18446744073709551612 | +-----------------------+ | 3 | +-----------------------+ 5, bitwise right SHIFT www.2cto.com mysql> Select 3>>1; &N Bsp +------+ | 3>>1 | +------+ | 1 | +------+6, bitwise left shift mysql> Select 3<<1; & nbsp ------+ | 3<<1 | +------+ | 6 | +------+ Five, operator precedence order highest priority:= &NB Sp 1 |, or, xor 2 &&, and 3 between, case, when, then, ELSE&NB Sp 4 =, <=>, >=,, <=, <, <>,! =, is, like, REGEXP, in &NBS P 5 | 6 & 7 <<, >> 8-, +&N BSp 9 *,/, DIV,%, mod ^ One-(unary minus), ~ (unary bit inversion) , not Lowest priority BINARY, COLLATE