当前位置:网站首页>MySQL basic addition, deletion, modification and query of SQL statements
MySQL basic addition, deletion, modification and query of SQL statements
2022-07-06 17:25:00 【Cute new vegetable dog】
CRUD
Insert sentence
insert into `good` (id,good_name,price) values(11,' Apple mobile phone ',5000);
-- Table name Name Name Name value
- insert Statement notes
- The inserted data should be of the same data type as the field
- The length of the data should be within the specified range , for example : One length cannot be 80 The string of is added to the length of 40 In the column of
- stay values The data positions listed in must correspond to the arrangement positions of the added columns
- Character and date type data should be enclosed in single quotation marks
- Columns can be inserted with null values 【 Provided that this field is allowed to be empty 】
- insert into tab_name ( Name …) values(),(),()…;
- If you are adding data to all fields in the table , You may not write the field name in front
- Use of default values , When a field value is not given , If there is a default value, it will be added , Otherwise, the report will be wrong .
update sentence
update good set price = price + 1000 where good_name = ' Apple mobile phone ';
- Use details
- update Syntax to update columns in the original table row with new values .
- set Clause indicates which columns to modify and which values to assign .
- where Clause specifies which rows should be updated , If not where Clause , Update all rows ( Record )
- If you need to modify multiple fields , Can pass set Field 1 = value 1, Field 2 = value 2…
delete sentence
delete from good where good_name = ' Apple mobile phone ';
- Use details
- If not applicable where Clause , All data in the table will be deleted
- Delete Statement cannot delete the value of a column ( You can use update Set to null perhaps ‘’)
- Use delete Statement only delete records , Don't delete the table itself . If you want to delete a table , Use drop table sentence .
select sentence
Basic grammar
select [distinct] *|{column1,column2,....} from table_name;
- matters needing attention
- select Specify which columns of data to query
- column Specifies the column name
- * Number means to query all columns
- from Specify which table to query
- distinct Optional , It refers to the time of query results , Whether to remove duplicate data
-- Count the total score of each student
select `name`,(chinese+english+math) from student;
-- Add 10 branch
select `name`,(chinese+english+math+10) from student;
-- Use an alias to represent the student's total score
select `name` as ' name ',(chinese+english+math) as total_score from student;
where Operators often used in
Comparison operator
> < <= >= = <> != -- Greater than , Less than , Greater than ( Less than ) be equal to , It's not equal tobetween ... and ... -- The value displayed in an areain(set) -- Displayed in the in Values in the list , for example ,in(100,200) This set It's a collection , Does not mean intervallike ' Zhang pattern' not like '' -- Fuzzy queryis null -- Determine whether it is nullLogical operators
and -- Multiple conditions hold at the same time or -- Any of several conditions holds not -- Don't set up , for example :where not (salary>100);
select * from student where (chinese+english+math) > 200 and math< chinese and `name` like ' Han %';
-- This Han % Indicates a string beginning with Han , No matter how many characters there are after Han .
-- Han _ Indicates a string beginning with Han , however There can only be one character after Han .
- between …and…( Closed interval )
select * from student where english between 80 and 90;
Use order by Clause sort query results
select column1,column2,... from tablename order by column asc|desc;
- order by Specify sorted columns , The sorted column can be either the column name in the table , It can also be select The column name specified after the statement
- asc Ascending 【 Default 】,desc Descending
- order by Clause should be in select End of statement
select * from student order by math;-- The default is ascending
select * from student order by math desc -- according to math Grades in descending order
select `name`,(chinese+math+english) as total_score from student order by total_score;
-- Arrange the total scores in ascending order
select `name`,(chinese+math+english) as total_score from student order by total_score desc;
-- Arrange the total scores in descending order
边栏推荐
- MySQL digital function
- How does wechat prevent withdrawal come true?
- 【逆向中级】跃跃欲试
- Introduction to spring trick of ByteDance: senior students, senior students, senior students, and the author "brocade bag"
- Flink 解析(七):时间窗口
- À propos de l'utilisation intelligente du flux et de la carte
- Program counter of JVM runtime data area
- C# WinForm系列-Button简单使用
- C# WinForm中DataGridView单元格显示图片
- 唯有学C不负众望 TOP3 Demo练习
猜你喜欢

Instructions for Redux

High performance mysql (Third Edition) notes

How does wechat prevent withdrawal come true?

手把手带你做强化学习实验--敲级详细
![[reverse primary] Unique](/img/80/9fcef27863facc9066e48f221c6686.png)
[reverse primary] Unique

Wu Jun trilogy insight (IV) everyone's wisdom

【逆向】脱壳后修复IAT并关闭ASLR

Shawshank's sense of redemption

The daemon thread starts redis and modifies the configuration file

TCP's three handshakes and four waves
随机推荐
JVM垃圾回收概述
06个人研发的产品及推广-代码统计工具
数据仓库建模使用的模型以及分层介绍
连接局域网MySql
02个人研发的产品及推广-短信平台
After idea installs the plug-in, restart the plug-in and disappear
JUnit unit test
轻量级计划服务工具研发与实践
【逆向】脱壳后修复IAT并关闭ASLR
8086 CPU internal structure
mysql的列的数据类型详解
Wu Jun's trilogy insight (V) refusing fake workers
【逆向初级】独树一帜
Activiti directory (I) highlights
Login to verify the simple use of KOA passport Middleware
Flink 解析(七):时间窗口
唯有学C不负众望 TOP4 S1E6:数据类型
唯有学C不负众望 TOP2 p1变量
Data transfer instruction
[ciscn 2021 South China]rsa writeup