当前位置:网站首页>MySQL must know and know!!! Reading this article is enough!!!
MySQL must know and know!!! Reading this article is enough!!!
2022-07-27 10:38:00 【sun*san】
Catalog
Search with regular expressions
Match one of several characters
Splices join values together to form a single value
It's called AS Key words are given to
Perform arithmetic calculations
Upper() The function converts text to uppercase
Common text processing functions
Date and time processing functions
Commonly used date and time processing functions
inductive SELECT Order of clauses
SELECT sentence
keyword
SELECT * FROM products "*" wildcard
SELECT DISTINCT id FROM products DISTINCT Weight removal
SELECT name FROM products LIMIT 5 LIMIT instructions MySQL Return no more than five lines
LIMIT3,4 Refers to the subordinate line 3 At the beginning 4 That's ok
Sort
Single column sort
SELECT name FROM products ORDER BY name
take name Columns are sorted alphabetically
Sort by multiple columns
SELECT id, name, price FROM products ORDER BY price ,name
First by price, then by name
Specify sorting direction
SELECT id,price,name FROM products ORDER BY price DESC
DESC null ( Specify only the column names that precede )
If you want to sort in descending order on multiple columns , You need to specify... For each column DESC keyword
Sort + Limit
SELECT price FROM products ORDER BY price DESC LIMIT 1
WHERE keyword
SELECT name,price FROM products WHERE price = 2.50
ORDER BY Should be located WHERE after
WHERE Clause operator <,>,=,>=,<=,!=,<>,BETWEEN
WHERE price BETWEEN 5 AND 10
WHERE price IS NULL
* Cannot return with NULL Row of values
AND OR key word
WHERE id=1003 AND price<=10
AND Join keywords
OR Or key words

use Parentheses clearly Group
IN The operator

IN And OR The function of has the same function , however IN It's better
NOT The operator
NOT WHERE Keyword used in clause to negate a condition followed by a condition
SELECT name,price FROM products WHERE id NOT IN(1002,1003)
It means match 1002 and 1003 In addition to the id
wildcard
LIKE wildcard
% wildcard
% Means any character appears any number of times
for example , Find all the words jet The first product , You can use the following statement
SELECT id,name FROM products WHERE name LIKE ‘jet%’;
Empathy ‘%anvil’ Can match any location containing text anvil Value
‘s%e’ Can match to s Start with e All values at the end
% Wildcards cannot match NULL
Be careful MYSQL Search can be case sensitive , It depends on your MySQL Configuration of
Underline “_” wildcard
Underline and % The usage is the same , But underscores can only match a single character, not multiple characters .
Take a chestnut
SELECT id,name FROM products WHERE name LIKE ‘_ ton anvil’;
Search with regular expressions
REGEXP
SELECT name FROM products WHERE name REGEXP ‘1000’ ORDER BY name;


MySQL Regular expressions for are not case sensitive , To be case sensitive , Can be used BINARY keyword , for example
"." Can match any character
WHERE name REGEXP BINARY ‘JetPack .000’
Conduct OR matching
WHERE name REGEXP ‘1000|2000’ ORDER BY name
Match one of several characters
SELECT name FROM products WHERE name REGEXP ‘[123] Ton’ ORDER BY name
Regular expressions are used here [123] Ton, It means match 1 or 2 or 3, Function like IN keyword , yes [1|2|3] Abbreviation
Character sets can also be negated , Place a... At the beginning of the collection "∧" that will do , for example [∧123], You can match the division 123 Other characters
“-” character
“-” It can be used to define a range , for example [1-9],[a-z] Fine
Take a chestnut
SELECT name FROM products WHERE name REGEXP ‘[1-5]Ton’
“\\” Match special character
To match these keyword characters , for example “-”,“.” How should we do this
To match special characters , It must be used. “\\” As the leader , for example
SELECT name FROM products WHERE name REGEXP ‘\\.’
“\\” Also used to refer to metacharacters

To match the backslash “\” Character itself , Need to use "\\\"
Match character class

The regular expression section is omitted
Create calculated fields
When we need to retrieve the transformation from the database , Calculation , Or formatted data , Calculation fields are needed
Splices join values together to form a single value
The solution is to splice the two columns , You can use Concat() Function to splice two columns

It's called AS Key words are given to
SELECT Concat(RTrim(name,' (',RTrim(country), ')') AS title FROM vendors ORDER BY name ;
The sentence itself is the same as the previous sentence , But it indicates SQL Create a calculation named title Calculation field of , Any client can reference this column by name
RTrim You can remove all the blanks on the right ,LTrim You can remove all the blanks on the left ,Trim You can remove the spaces on both sides
Perform arithmetic calculations

![]()
MySQL function
Text processing function
Upper() The function converts text to uppercase
SELECT name,Upper(name) AS name——upcase
FROM vendors
ORDER BY name

Common text processing functions



Date and time processing functions
Commonly used date and time processing functions
MySQL Date format used , Date format must be yyyy-mm-dd.
for example
SELECT id ,num FROM orders WHERE date=‘2005-09-01’;
To retrieve all the data in September , You can use :
SELECT id,num FROM orders WHERE Date(order_date) BETWEEN '2005-09-01' AND '2005-09-30';
or

Numerical processing function

Summary data
Concept
We often need to aggregate data without actually retrieving them , At this time, we need to use the aggregation function
Examples of this type of retrieval are :
* Determine the functions in the table
* Get the sum of row groups in the table
* Find the maximum, minimum and average values in the table
Aggregation function

Take the first function AVG() For example
SELECT AVG(price) AS avg_price FROM products;
The return value is avg_price, by products The average price of all products in the table




DINTINCT Parameters
DINTINCT Weight removal can be achieved , The same number is not included in the calculation range of the aggregate function
The data packet
GROUP BY Clause
Take a chestnut


GROUP BY It can be grouped according to the specified data , Then aggregate the data in each group

Filter grouping
We know WHERE It has the function of filtration , however WHERE Is to filter rows , For grouping , We can use HAVING Clause to filter the grouping , Syntax and WHERE identical .
for example

WHERE And HAVING At the same time

inductive SELECT Order of clauses

Subquery
That is, queries nested in other queries
—— To be continued ——
x
边栏推荐
- A few simple steps to realize the sharing network for industrial raspberry pie
- The core concept and fast practice of shardingsphere
- php生成文字图片水印
- [brother hero June training] day 28: dynamic planning
- Matlab create text cloud
- mount.nfs: access denied by server while mounting解决
- Eslint的报错信息Module Error (from ./node_modules/[email protected]@eslint-loader/index.js)解决方法
- Detailed analysis of graphs of echats diagram les miserables (chord diagram)
- 【英雄哥六月集训】第 24天: 线段树
- 解决ORCLE-ORA-01122 01110 01210
猜你喜欢

Ant advanced -path and fileset

Oracle resizing data files

Data types and variables

flask_ Output fields in restful (resources, fields, marshal, marshal_with)

hdu5288(OO’s Sequence)

Matlab底层源代码实现图像的中值滤波(用于消除图像上一些杂点)
[email protected]@eslint-loader/index.js)解决方法"/>Eslint的报错信息Module Error (from ./node_modules/[email protected]@eslint-loader/index.js)解决方法

Gamer questions

FTP 服务器

PHP generates text and image watermarks
随机推荐
Oracle resizing data files
Warning: remote head references to nonexistent ref, unable to checkout error messages
[brother hero June training] day 28: dynamic planning
Family Trivia
The core concept and fast practice of shardingsphere
服务器访问速度
warning package. Json: no license field error
Mysql死锁、悲观锁、乐观锁
[brother hero's June training] day 26: check the collection
File upload vulnerability bypass method
Matlab sound classification based on short-time neural network
一起学习C语言:结构体(二)
声音处理之-梅尔频率倒谱系数(MFCC)
DES/3DES/AES区别
Oracle 11g manual memory management
Analysis of heterogeneous computing technology
数据库操作基础语句
ORACLE 11g手动内存管理
这种动态规划你见过吗——状态机动态规划之股票问题(上)
mount.nfs: access denied by server while mounting解决