当前位置:网站首页>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 :

边栏推荐
- El table highly adaptive
- Computing architecture of microblog comments
- 安装spark + 用命令运行scala相关项目 + crontab定时执行
- 【深入理解TcaplusDB技术】Tmonitor系统升级
- 什么是泛型以及在集合中泛型的使用[通俗易懂]
- [deeply understand tcapulusdb technology] table management of document acceptance
- 哈希竞猜游戏系统开发如何开发?哈希竞猜游戏系统开发应用详情案例及源码
- 存在重复元素III[利用排序后的有序性进行剪枝]
- [deeply understand tcapulusdb technology] transaction execution of document acceptance
- RMAN备份数据库_使用RMAN做拆分镜像(split mirror)备份
猜你喜欢

【深入理解TcaplusDB技术】单据受理之表管理

解析数仓lazyagg查询重写优化

Install spark + run Scala related projects with commands + crontab scheduled execution

Good news | Haitai Fangyuan has passed the cmmi-3 qualification certification, and its R & D capability has been internationally recognized

Uncover ges super large scale graph computing engine hyg: Graph Segmentation

【深入理解TcaplusDB技术】TcaplusDB新增机型

LeetCode力扣(剑指offer 26-30)26. 树的子结构 27. 二叉树的镜像 28. 对称的二叉树 29. 顺时针打印矩阵 30. 包含min函数的栈

Computing architecture of microblog comments
![[in depth understanding of tcapulusdb technology] business guide for creating doc acceptance](/img/e5/9c902f5d6aaeb7113e82d2c1084005.png)
[in depth understanding of tcapulusdb technology] business guide for creating doc acceptance

How can the self-supporting number evaluation be safer for cross-border e-commerce platforms such as Amazon, eBay, shopee, lazada, express, Wal Mart and Alibaba international?
随机推荐
[deeply understand tcapulusdb technology] tmonitor system upgrade
jvm问题复盘
. Net worker service adding a serial log record
Pycharm 使用过程中碰到问题
Detailed explanation of route add command
C#泛型类案例
Fixed frequency and voltage regulation scheme of Qi v1.2.4 protocol
anaconda下载清华源
Matlab中图形对象属性gca使用
C# asp,net core框架传值方式和session使用
Wechat applet reports an error: request:fail URL not in domain list
RMAN backup database_ Skip offline, read-only, and inaccessible files
Introduction to microservices
1. Understanding of norm
【深入理解TcaplusDB技术】TcaplusDB机型
Dell r530 built in hot spare status change description
什么是算子?
How can the self-supporting number evaluation be safer for cross-border e-commerce platforms such as Amazon, eBay, shopee, lazada, express, Wal Mart and Alibaba international?
[in depth understanding of tcapulusdb technology] tcapulusdb construction data
What is the ranking of the top ten securities companies? Is it safe to open a mobile account?