当前位置:网站首页>Getting started database days2
Getting started database days2
2022-07-23 22:47:00 【Xiao Wu has an idea】
- Reference books 《MySql From entry to mastery 》
- Learning video 【 Han Shunping said MySQL】 Zero basis a week to learn MySQL -sql mysql course mysql video mysql introduction _ Bili, Bili _bilibili
- Mengxin beginner level , If there is any mistake, please give advice , Not very grateful
Catalog
Use expressions to operate on the columns of the query
edit Where Operators commonly used in statements
edit Use order by Clause sort query results
insert Statement notes
- The inserted data should be of the same data type as the field For example 'abc' Add to int The type will be wrong
- The length of the column should be within the specified range , for example : You can't change a length to 80 The string of is added to a 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 data are contained in single quotation marks
- Columns can be inserted with null values 【 The premise is that the field can be empty 】,insert into table value(null)
- If you are adding data to all fields in the table , You can not write the previous field name
- 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 . If a column is not specified not null , When adding data , There is no given value , Will default to null . If we want to specify the default value of a column , You can specify... When creating a table
The demonstration is as follows :
Create the table first s1
CREATE TABLE s1(
id INT,
`name` VARCHAR(10),
price DOUBLE);
-- Add data
INSERT INTO s1 (id,`name`,price)
VALUES(10,' Huawei mobile phones ',3999);
INSERT INTO s1 (id,`name`,price)
VALUES(10,' Apple mobile phone ',3999);
SELECT * FROM s1;

When the added value corresponds to id As a 'abc' Times wrong

When added name The value exceeds the specified 10 There are errors in characters


notes : If in price DOUBLE Then write it down NOT NULL, Then this cannot be empty
Add data to all fields , You can omit the field name ![]()


Here it is price After setting the default value 100, Even if you don't write, it will be assigned automatically 100
update Statement notes
UPDATE Table name
SET col_name1=expr1[,col_name2=expr2 ...]
[WHERE where_definition]
Modify the table to table t99 To demonstrate

1. Change all employee salaries to 5000 element .[ If you don't have where Conditions , Will modify all records , Therefore, we need to be cautious ]
UPDATE t99 SET salary =5000
SELECT * FROM t99
2. Name is Goblins The salary of the employee is revised to 3000 element
UPDATE t99
SET salary =3000
WHERE user_name =' Goblins '
3. take Old monster My salary is increased on the original basis 1000 element


4. Modify multiple columns at the same time


Delect Use of statements
The grammar is as follows :
delete from Table name
[WHERE where_definition]
![]()

Delete all records in the table
![]()
Delete sentence Can't 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 .drop table Table name ;
Select Use of statements
Basic grammar :
SELECT [DISTINCT] * | {column1, column2 . column3..}
FROM Table name
Create a student table

Look up the names of all the students and their English scores
SELECT `name`,english FROM student;
De duplication of Chinese scores during query
SELECT DISTINCT chinese FROM student
If in chinese Write in front name etc. , Only when the data corresponding to the corresponding column is repeated can the duplication be removed
Use expressions to operate on the columns of the query
SELECT * |{column | expression ,column2| expression, .. }
FROM Table name ;
example : Count the total score of each student


Use aliases to indicate student scores

Where Operators commonly used in statements

Query all English scores greater than 80 People who

Query math is greater than 80 branch also id Greater than 4 People who

Query people whose English scores are greater than Chinese scores

Total query score greater than 200 branch , And the math score is less than the Chinese score , A student surnamed Zhu


Query English scores in 80-90 Between the students
![]()

Query English scores in 80,90,70 Of the students

Check all students surnamed Liu

Use order by Clause sort query results
SELECT column1 ,column2 ,column3..
FROM table;
order by column asc|desc, ...
- Order by Specify the columns to arrange , 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
example : Sort the math grades and output them ( Descending )
![]()
Sort the total score from high to low and output ( Descending )

Will all ‘ Bucket ’ The total score of students with surnames is sorted from low to high and then output ( Ascending )


The above is today's video notes , In case of infringement, please contact me to delete .
God helps those who help themselves , Come on with Xiao Wu !
边栏推荐
- Internet协议栈 TCP/IP模型 物理层、链路层、网络层、传输层、应用层的作用
- Array - 59. Spiral matrix II
- 小说里的编程 【连载之十六】元宇宙里月亮弯弯
- Microsoft SQL Server database language and function usage (XIII)
- Altium Designer - schematic diagram of Arduino uno & PCB diagram (self-made Arduino board)
- LeetCode高频题53. 最大子数组和,具有最大和的连续子数组,返回其最大和
- How about opening an account for Haitong Securities? Is it safe
- About synchronizing data from computer to mobile
- Drools (1): introduction to drools
- el-select下拉框多选远程搜索反显
猜你喜欢

Introduction and project development of MVVM and mvvmlight (I)

ospf终极实验——学会ospf世纪模板例题

【golang学习笔记】包(package)的使用

I, AI doctoral student, online crowdfunding research topic

众邦科技又一潜心力作 —— 陀螺匠 OA 系统

unity visual studio2019升级到2022版本(扔掉盗版红渣)

作为开发,你不得不知道的三个性能测试工具|Jmeter、Apipost、JMH使用指南

How to add an operator in ONEFLOW

Still worrying about xshell cracking, try tabby

Leetcode high frequency question 53. maximum subarray sum, continuous subarray with maximum sum, return its maximum sum
随机推荐
Memory search - DP
Still worrying about xshell cracking, try tabby
DeFi項目的盈利邏輯 2021-04-26
D1-H 开发板——哪吒 开发入门
D1-h development board - Introduction to Nezha development
Absl tutorial (4): strings Library
QT set cache and compile output path
小说里的编程 【连载之十七】元宇宙里月亮弯弯
Rosbag file recorded by LIDAR point cloud data is converted into CSV file
[C language] address book (static version)
Stm32+esp8266+mqtt protocol connects Alibaba cloud Internet of things platform
ES6箭頭函數的使用
02. Supplement of knowledge related to web page structure
Notes on network segment CIDR
【golang学习笔记】flag包的简单使用,命令行解析
STM32单片机使用ADC功能驱动手指检测心跳模块
LeetCode高频题62. 不同路径:机器人从左上角到右下角的路径有多少条?纯概率排列组合问题,而不是动态规划题
Data sorting and usage before torchvision.datasets.imagefolder
疯狂的牛市,下半场何去何从?2021-04-30
狂神redis笔记10
