当前位置:网站首页>Operators in MySQL
Operators in MySQL
2022-07-28 00:53:00 【richest_ qi】
List of articles
Arithmetic operator
Arithmetic operator , Include +、-、*、/ perhaps DIV、% perhaps MOD( Remainder or modulus ).
- MySQL in ,
+Just add the numbers , If a non numeric type is encountered ,MySQL Will first try to convert it to a number , If the conversion fails , It is regarded as a numerical value 0 Handle . in other words , There is Implicit conversion . - MySQL in , String splicing uses functions
CONCAT(str1,str2,...)Realization . - Null values participate in the operation , The result of the operation is still null .
- MySQL in , Divisor is 0 when , The result is null , namely
NULL.
+ Just add the numbers
# MySQL in ,+ Just add the numbers , If a non numeric type is encountered ,MySQL Will first try to convert it to a number , If the conversion fails , It is regarded as a numerical value 0 Handle . in other words , There is Implicit conversion .
SELECT 100 + '2'
FROM DUAL; -- return 102
SELECT 100 + 'A'
FROM DUAL; -- return 100
SELECT 'A' + 'B'
FROM DUAL; -- return 0
String splicing function CONCAT()
# MySQL in , String splicing uses functions CONCAT() Realization
SELECT CONCAT('HEL','LO')
FROM DUAL; -- return HELLO
SELECT CONCAT('a','b','c')
FROM DUAL; -- return abc
Null values participate in the operation , The result is still null
SELECT 100 + NULL
FROM DUAL; -- return NULL
Divisor is 0 when , The result is empty.
SELECT 100/0
FROM DUAL; -- return NULL
Comparison operator
Comparison operator , Include =、<=>、<> perhaps !=、<、<=、>、>=,
Also include IS NULL、IS NOT NULL、ISNULL()、LEAST()、GREATEST()、BETWEEN AND、IN()、NOT IN()、LIKE、REGEXP、RLIKE.
=, The equal sign operator . If one side is numerical , The other side is non numeric , Then there is implicit conversion . namely , First try to convert non numeric values to numeric values , If the conversion fails , It is regarded as a numerical value 0 Handle .=, The equal sign operator . If both sides are strings , Compare the characters in the string ANSI code .=, The equal sign operator , If either side appearsNULL, The result of the comparison isNULL.<=>, Security equals operator . and=similar , The difference lies in ,<=>It can be done toNULLJudge .- The judgment field is
NULL:Field <=>NULL、Field IS NULL、ISNULL( Field ). - The judgment field is not
NULL:NOT Field <=>NULL、Field IS NOT NULL、NOT ISNULL( Field ). BETWEEN Conditional lower bound AND Conditional upper bound, Including boundaries .- Use
LIKEFuzzy query , among ,%, A character representing an indefinite number . Can represent 0 Characters , Can represent 1 Characters , It can also represent multiple characters ._, Represents any character .\, Escape character .ESCAPE character, Specify a character as an escape character .
REGEXP, Regular matching . Common wildcards are as follows ,^, Match the beginning .$, Match the end .., Matches any character .*, matching 0 One or more characters in front of it . such as ,x*, Match any number ofxcharacter ;[0-9]*, Match any number of numbers ;*, Match any number of any characters .[], Match any character in brackets . such as ,[abc], matchingaorborc;[a-zA-Z], Match any uppercase and lowercase letters ;[0-9], Match any number .
= and <=>
# If one side is numerical , The other side is non numeric , Then there is implicit conversion . namely , First try to convert non numeric values to numeric values , If the conversion fails , It is regarded as a numerical value 0 Handle .
SELECT 1='1',1='a',0='a','1'=1,'a'=1,'a'=0
FROM DUAL;
-- return 1 0 1 1 0 1
# If = On both sides are strings , Compare the characters in the string ANSI code
SELECT 'a'='a','ab'='ab','a'='b'
FROM DUAL;
-- return 1 1 0
# =, The equal sign operator , Either side appears NULL, The results for NULL
SELECT 1=NULL,NULL='a',NULL=NULL
FROM DUAL;
-- return NULL NULL NULL
# <=>, Security equals operator , and =( The equal sign operator ) similar
SELECT 1<=>'1',1<=>'a',0<=>'a','1'<=>1,'a'<=>1,'a'<=>0
FROM DUAL;
-- return 1 0 1 1 0 1
SELECT 'a'<=>'a','ab'<=>'ab','a'<=>'b'
FROM DUAL;
-- return 1 1 0
# <=>, Security equals operator , It can be done to NULL Judge
SELECT 1<=>NULL,NULL<=>'a',NULL<=>NULL
FROM DUAL;
-- return 0 0 1
SELECT *
FROM employees
WHERE commission_pct <=> NULL;
-- return 72 rows
IS NULL、IS NOT NULL and ISNULL()
# Query table employees in ,commission_pct by NULL The data of
SELECT *
FROM employees
WHERE commission_pct <=> NULL;
SELECT *
FROM employees
WHERE commission_pct IS NULL;
SELECT *
FROM employees
WHERE ISNULL(commission_pct);
# Query table employees in ,commission_pct Not for NULL The data of
SELECT *
FROM employees
WHERE NOT commission_pct <=> NULL;
SELECT *
FROM employees
WHERE commission_pct IS NOT NULL;
SELECT *
FROM employees
WHERE NOT ISNULL(commission_pct);
BETWEEN … AND …
# Check salary at [6000,8000] Employee information within the scope
SELECT *
FROM employees
WHERE salary BETWEEN 6000 AND 8000;
SELECT *
FROM employees
WHERE salary>=6000 AND salary<=8000;
SELECT *
FROM employees
WHERE salary>=6000 && salary<=8000;
# The salary inquiry is not available [6000,8000] Employee information within the scope
SELECT *
FROM employees
WHERE salary NOT BETWEEN 6000 AND 8000;
SELECT *
FROM employees
WHERE salary<6000 OR salary>8000;
SELECT *
FROM employees
WHERE salary<6000 || salary>8000;
IN() and NOT IN()
# Inquire about department_id by 10,20,30 Employee information
SELECT *
FROM employees
WHERE department_id IN (10,20,30);
SELECT *
FROM employees
WHERE department_id=10 OR department_id=20 OR department_id=30;
# Query salary is not 6000,7000,8000 Employee information
SELECT *
FROM employees
WHERE salary NOT IN(6000,7000,8000);
SELECT *
FROM employees
WHERE salary<>6000 && salary<>7000 && salary<>8000;
Fuzzy query :LIKE
# Inquire about last_name Contains characters 'a' Employee information
SELECT last_name
FROM employees
WHERE last_name LIKE '%a%';
# Inquire about last_name In characters 'a' Employee information at the beginning
SELECT last_name
FROM employees
WHERE last_name LIKE 'a%';
# Inquire about last_name Contains both characters 'a' Also contains characters 'e' Employee information
SELECT last_name
FROM employees
WHERE last_name LIKE '%a%' AND last_name LIKE '%e%';
SELECT last_name
FROM employees
WHERE last_name LIKE '%a%e%' OR last_name LIKE '%e%a%';
# Inquire about last_name The second character is 'a' Employee information
SELECT last_name
FROM employees
WHERE last_name LIKE '_a%';
Logical operators
Logical operators , Include NOT or !,AND or &&、OR or || 、XOR ( Logical XOR ).
AND and OR Can be used together , And AND The priority ratio OR High priority .
An operator
An operator , Include ~( According to the not )、&( Bitwise AND )、|( Press bit or )、^( Bitwise XOR )、>>( Right shift to position )、<<( Move left according to position ).
边栏推荐
- MySQL limit usage and large paging problem solving
- Network equipment hard core technology insider firewall and security gateway (12) the mystery of zero contact office
- Network equipment hard core technology insider firewall and security gateway (V) security double repair method
- The program design questions of the 11th national competition of Bluebridge cup single chip microcomputer
- How does JMeter solve the problem of garbled code?
- Impulse attends the 2022 Forum on safe circulation of data elements Online - a special session in the field of government affairs, and helps the construction and innovative development of big data for
- Read cmake in one article
- Y79. Chapter IV Prometheus' monitoring system and practice -- Prometheus' service discovery mechanism (10)
- 激活最大化
- 网络设备硬核技术内幕 防火墙与安全网关篇 (六) 安全双修大法 下
猜你喜欢

What are the namespaces and function overloads of + and @ in front of MATLAB folder

Basic operations of MySQL database (3) --- Based on fields
![[leetcode] 547. Number of provinces (medium)](/img/15/d49d18151c47e318fe7acabdd616e6.png)
[leetcode] 547. Number of provinces (medium)

IP address & subnet mask

Basic operations of MySQL database (I) --- Based on Database
![[bre] software build release automation](/img/c6/daead474a64a9a3c86dd140c097be0.jpg)
[bre] software build release automation

Read cmake in one article

Postman下载、使用教程

leetcode:1997. 访问完所有房间的第一天【跳跃dp】

mysql数据库的基本操作(二)-——基于数据表
随机推荐
What are the namespaces and function overloads of + and @ in front of MATLAB folder
startUMl
激活最大化
Arm releases the new a78/g78/n78 kernel! There is also a cortex-x Series CPU that supports customization
Threejs personal notes
网络设备硬核技术内幕 防火墙与安全网关篇 (九) 虚拟化神器 (下)
FFT 采样频率和采样点数的选取
Jerry's Bluetooth can only link back to the last device [article]
Strong collaboration and common development! Intel and Taiyi IOT held a seminar on AI computing box aggregation services
[CruiseControl]Build Result JSP
Numpy has no unsqueeze function
融云 IM & RTC 能力上新盘点
大众中国豪掷80亿,成国轩高科第一大股东
LeetCode_位运算_中等_137.只出现一次的数字 II
[leetcode] 547. Number of provinces (medium)
Matlab | those matlab tips you have to know (2)
一周年创作纪念日,冲吧少年郎
leetcode 452. Minimum Number of Arrows to Burst Balloons 用最少数量的箭引爆气球(中等)
[bre] software build release automation
[must read for new products] valuation analysis of Meishi technology, distributed audio-visual products and Solutions