当前位置:网站首页>Addition, deletion, modification and query of mysql~ tables (detailed and easy to understand)
Addition, deletion, modification and query of mysql~ tables (detailed and easy to understand)
2022-06-25 18:26:00 【Zebra and running】
Catalog
(1). Single line data + Insert all columns
(2). Multi row data + Specify column insertion
(3). The query field is an expression
(5). duplicate removal :DISTINCT
(7). ( important ) Conditions of the query :WHERE
4).NULL Query for :IS [NOT] NULL
(9). Paging query :LIMIT(MySQL special )
eg: Use paging query to select the students with the second Chinese score
6. The main content is summary
(1). How to delete Id Maximum value
1.CRUD
- notes : stay SQL Can be used in “-- Space + describe ” To indicate a comment
- CRUD That is, increase (Create)、 Inquire about (Retrieve)、 to update (Update)、 Delete (Delete) An acronym for four words .
2. newly added (Create)
grammar :

give an example :

(1). Single line data + Insert all columns

(2). Multi row data + Specify column insertion

1. The string in the database is a single quotation mark
2. Generally, the database should have a unique field to identify the table , stay java In order to correspond to the database , That also needs to have such an attribute
3. Write later , Try to use only the writing method of the specified column insertion , Because if you don't specify column insertion , In the future, if you add a field to your table , Then the previous statement will report an error
4. Annotation syntax :-- Space
3. Inquire about (Retrieve)
grammar :

(1). Full column query

(2). Specified column query

(3). The query field is an expression

When the query field is an expression , He'll check later , Calculate by yourself and then output
(4). Alias
Specify aliases for columns in query results , Represents the returned result set , Use alias as the name of the column .
grammar :


- Tips: Alias “ Total score ” I can add as
- notes : Here you can see , The data we show here is the result set returned to us by the database . The black box here is the client , The database is the server
(5). duplicate removal :DISTINCT
Use DISTINCT Keyword to de duplicate a column of data :

distinct Put in front of the field to be specified , And only one field can be added
(6). Sort :ORDER BY
Java Sort :(1) Algorithmic sorting (2)java Compare interfaces for sorting
grammar :

1. No, ORDER BY Clause , The order of return is undefined , Never rely on this order
2. NULL Data sorting , Treat as less than any value , The ascending order appears at the top , Descending order appears at the bottom
3. Use expressions and aliases to sort

4. You can sort multiple fields , The order of priority follows the order of writing

5.order by In general, and limit Use it together , Used to select the first three elements .
(7). ( important ) Conditions of the query :WHERE
Comparison operator :

The comparison operators and java The comparison operators inside are different
- = It's a comparison operator , Means to judge equal , No more java Inside == 了
- As long as you know = Can , It doesn't mean just knowing != Just go
Logical operators :

1). The basic query

- Be careful WHERE Conditions can be expressed as , But you can't use aliases .
2). Range queries
--BETWEEN ... AND ...

--IN
3). Fuzzy query :LIKE

- % The match is 0 Characters or more , For example, there is only one ‘ Grandchildren ’, That's only ‘ Grandchildren %’ Can match
- _ The match is a character
4).NULL Query for :IS [NOT] NULL

(8). Use and query of dates
1. Create a table with dates

- Here we need to set a default value for the date , But I don't have to set the default value myself .
- Set the default value to null That's all right.
2.mysql Default date format :yyyy-MM-dd HH:mm:ss
Insert data with date

3. Query date field

Like other fields , You can also query between-and.
4.

(9). Paging query :LIMIT(MySQL special )
grammar :

- s It's the offset ( Just offset a few first ),n Indicates the number of filter results
- the second LIMIT s,n Means screening n Bar result , From s Data starts
- Third LIMIT n OFFSET s Means screening n Bar result , From s Data starts
- This is not to suggest a third , The second kind can also , It depends on which one you use more smoothly , One is to s after n, The other is to n after s, I suggest the third , Because no s The time is LIMIT n
- Order by In general, and limit Use it together
eg: Use paging query to select the students with the second Chinese score
select * from exam_result order by chinese desc limit 1 offset 1
4. modify (Update)
grammar :


- stay set When , If the length of the value exceeds the length given when creating the table , Will report a mistake .
- Like the last set chinese = chinese * 2; You may report an error
- If not where,order by And so on , That is, the values of the whole column of elements are modified
5. Delete (Delete)
grammar :


Be careful delete from table_name, There's nothing in the back , That is, the whole table is deleted , Be sure to pay attention to . To add where,order by,limit etc.
6. The main content is summary
(1). How to delete Id Maximum value
mysql in You can't specify target table for update in FROM clause The wrong meaning is to say , Not first select Give some values in the same table , Again update This table ( In the same sentence ).
error :
![]()
correct :
(2). Normal summary
newly added :

Inquire about :


modify :
![]()
Delete :

边栏推荐
- 将Graph Explorer搬上JupyterLab:使用GES4Jupyter连接GES并进行图探索
- el-table高度自适应
- new TypeReference用法 fastjson[通俗易懂]
- Use pagoda to set up mqtt server
- GNU nano
- There is a repeating element iii[pruning with ordered ordering]
- QT中QString包含“\u0000“的处理方式
- 【深入理解TcaplusDB技术】单据受理之创建游戏区
- RMAN备份数据库_跳过脱机,只读和不可访问的文件
- 【深入理解TcaplusDB技术】单据受理之创建业务指南
猜你喜欢
![[deeply understand tcapulusdb technology] one click installation of tmonitor background](/img/0a/742503e96a9b51735f5fd3f598b9af.png)
[deeply understand tcapulusdb technology] one click installation of tmonitor background

Optimization of lazyagg query rewriting in parsing data warehouse

【深入理解TcaplusDB技术】单据受理之创建业务指南

【深入理解TcaplusDB技术】集群管理操作

Chapter 4:win10 installing mingw64

158_ Model_ Power Bi uses DAX + SVG to open up almost all possibilities for making business charts
![[deeply understand tcapulusdb technology] tmonitor module architecture](/img/82/24a8502604fccb89fea9963c3f3495.png)
[deeply understand tcapulusdb technology] tmonitor module architecture

【深入理解TcaplusDB技术】TcaplusDB业务数据备份

anaconda下载清华源

深度学习网路模型
随机推荐
[deeply understand tcapulusdb technology] create a game zone
IVX 启航
RMAN备份数据库_使用RMAN做拆分镜像(split mirror)备份
Redis command string
OSError: Unable to open file (truncated file: eof = 254803968, sblock->base_addr = 0, stored_eof = 2
JSP页面运行却显示源码
RMAN backup database_ Duplexing backup sets
Anaconda download Tsinghua source
QT中QString包含“\u0000“的处理方式
[deeply understand tcapulusdb technology] tmonitor module architecture
Trample hole record -- a series of coincidences caused by thread pool rejection policy
158_模型_Power BI 使用 DAX + SVG 打通制作商业图表几乎所有可能
十大券商的排名是?手机开户安全么?
RMAN备份数据库_重启RMAN备份
Boiled peanuts
RMAN backup database_ catalogue
. How to exit net worker service gracefully
【深入理解TcaplusDB技术】TcaplusDB运维
How to open a stock account is it safe to open an account
The icon is missing. What does the URL come from with the jesssionid?