当前位置:网站首页>SQL novice
SQL novice
2022-07-27 06:06:00 【The last tripod】
Some introductions
database
Document warehouse
Database management system
Manage the warehouse ( Additions and deletions ) Such as MySQL
SQL
Database language
mySQL Some orders
SQL Case insensitive !!!
show databases;// See what databases are
use Database name ;// Use a database
creat database Database name ;// Create a database
show tables;// Check which tables are under a database
source Pathname ;// Import of this path sql file ,** No Chinese in the path **
desc(describe) Table name ;// Check the structure of the table
select version();// Inquire about MySQL Version number of
select database();// Query the current database name
The most basic unit of database : surface (table)
That's ok (row): data 、 Record
Column (column): Field
Each field contains : Field name 、 data type 、 Constraints, etc
SQL Sentence classification
DDL:
Data query language select…
DML:
Data operation language
insert delete update( Data addition, deletion and modification )
DDL:
Data definition language
creat drop alter( Addition, deletion and modification of table structure )
TCL:
Things control language
Transaction submission (commit) Things roll back (rollback)
DCL:
Data control language
SQL Inquire about
Simple query
select Field name from Table name ;// Query a field
select Field name 1, Field name 2 from Table name ;// Query multiple fields
select * from Table name ;// Query all fields ( Because of the need to * Convert to field name , So it's less efficient , It is not recommended to use
select Field name as Alias ;// When displaying, the field name is replaced by an alias , But the data in the table will not be modified ("," You can use a space instead of , If there are spaces in the alias, you can include the alias with a single )
select Field name + operation ;// Field operation
Conditions of the query
select Field name 1, Field name 2....from Table name where Conditions ;
- Relational operator ( The equal sign is =, The unequal sign has != and <>)
- between … and…( Note that the previous value should be smaller than the following value , Equate to …>= and …<=) Query between two values
- Logical operators and,or,not ** Be careful :** priority and Greater than or, If necessary, brackets should be used to contain
- in contain , Can be used instead of = for example select Field name where …in(… , …);
** Be careful :** Whether it is null Need to use is null or is not null To judge , because null It's not a value
Fuzzy query
like
% Match any number of characters
_ Match a character
like ‘%T%’// All contain T Of
like ‘T%’// Beginning with T Of
like ‘%T’// It ends with T Of
like ‘_T%’// The second letter is T Of
If the query content has _ Or is it % You can use escape characters \_ and %
Sort query
select ... from ... order by ...;// Default ascending order
select ... from ... order by ... desc;// Descending
select ... from ... order by ... asc;// Ascending
select ... from ... order by Field one asc, Field 2 asc;// The priority fields are arranged in ascending order , If they are equal, they are arranged in ascending order of field two
Group query
select ... from ... where ... group by ... order by...
Execution order :
- from
- where
- group by
- select
- order by
Data processing functions / Single line processing functions
characteristic : One input corresponds to one output
lower/upper Turn smaller / Big Write
substr( Intercepted string , Start subscript , Intercept length )** Starting subscript from 1 Start **
concat(s1,s2)// String splicing
length(s)// String length
trim(s)// String to space
str_to_data// String to date
data_format// Format date
round( The number , Number of decimal places reserved )// rounding ( The number of decimal places can be negative , Negative constrains forward )
rand()*100// Generate 100 Random number within
ifnull( data , Change to the value of )// If the data is null Just change to a specific value Add : stay SQL As long as there is null The results of the operations involved are null
case..when..then..when..then..else..end// Be similar to switch
Group function / Multiline processing functions
** characteristic :** Multiple inputs correspond to one output
min()// minimum value
max()// Maximum
avg()// Average
sum()// Sum up
count()// Count
Be careful :
- Grouping function must be grouped before use , If there is no grouping, the whole table is a group by default
- Grouping function calculation will ignore null
- * Represents a row of data , Because the data in one row cannot be all null, So you can use count(*) Count lines
- Grouping functions cannot be used directly in where clause ( because where The statement has not been grouped when it runs )
- Grouping functions can be used together , utilize “,” Division
- select If there is group by,select It can only be followed by the fields participating in the grouping and the grouping statements
边栏推荐
猜你喜欢

Lightroom Classic 2022 v11.4中文版「最新资源」

剪枝-量化-转onnx中文系列教程

所有常用排序的代码实现和介绍

Weidongshan digital photo frame project learning (IV) simple TXT document display (e-paper book)
![[first song] machine learning of rebirth - linear regression](/img/70/3efd9eacf88f55022eb52d096926f7.png)
[first song] machine learning of rebirth - linear regression

制作视频特效必备工具:NUKE 13

STM32-红外遥控

arcgis for js api(2) 获取要素服务的id集合

AE 3D particle system plug-in: Trapcode particle

PZK学C语言之数据类型,进制转换,输入输出,运算符,分支语句ifelse
随机推荐
【头歌】重生之我在py入门实训中(6):函数的定义与应用
编程学习记录——第8课【数组与设计五子棋,扫雷游戏】
制作视频特效必备工具:NUKE 13
【头歌】重生之我在py入门实训中(4):循环程序
李宏毅 2020 深度学习与人类语言处理 DLHLP-Conditional Generation by RNN and Attention-p22
链表回文判断
Cesium教程 (1) 界面介绍-3dtiles加载-更改鼠标操作设置
QGIS系列(1)-QGIS(server-apache) win10安装
安全帽反光衣检测识别数据集和yolov5模型
这是我的博客
Cmder的基础文件操作
【头歌】重生之深度学习篇-Keras(初级)
arcgis for js api(2) 获取要素服务的id集合
Day 2. Depressive symptoms, post-traumatic stress symptoms and suicide risk among graduate students
WebODM win10安装教程(亲测)
非重叠矩形中的随机点(力扣每日一题)
[song] rebirth of me in py introductory training (7): function call
malloc和new之间的不同-实战篇
C语言-程序的编译
Can it replace PS's drawing software?