当前位置:网站首页>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
边栏推荐
- 【头歌】重生之机器学习-线性回归
- 能替代ps的修图软件?
- 2022.6.10 stm32mp157 serial port clock learning
- C#线程锁(Lock)
- [song] rebirth of me in py introductory training (10): numpy
- Super remote connection management tool: Royal TSX
- 关于druid连接不上数据库的问题
- 1半自动爬虫
- Weidongshan digital photo frame project learning (II) displaying Chinese characters on LCD
- 【头歌】重生之我在py入门实训中(3): if条件语句
猜你喜欢

WebODM win10安装教程(亲测)

AE 3D粒子系统插件:Trapcode Particular

Redis在windows下的idea连接不上问题

STM32 infrared remote control

Lightroom classic 2022 v11.4 Chinese version "latest resources"

Kaggle调用自定义模块方法

2022.6.10 stm32mp157 serial port clock learning

Greedy high performance neural network and AI chip application research and training

性感素数(Acwing每日一题)
acwing每日一题 正方形数组的数目
随机推荐
编程学习记录--第2课【初识C语言】
STM32-红外遥控
力扣题解 动态规划(4)
1 semi automatic crawler
PS 2022 updated in June, what new functions have been added
Socket programming 1: using fork() to realize the most basic concurrency mode
Can it replace PS's drawing software?
QGIS系列(1)-QGIS(server-apache) win10安装
C语言-动态内存管理
哈希表的原理及哈希冲突的解决方法
[song] rebirth of me in py introductory training (7): function call
力扣题解 单调栈
Unity Shader 概述
【头歌】重生之我在py入门实训中(3): if条件语句
能替代ps的修图软件?
韦东山 数码相框 项目学习(一)在LCD上显示ASCII字符
力扣题解 二叉树(6)
编程学习记录——第8课【数组与设计五子棋,扫雷游戏】
C# Json编码在TCP通讯中的一些使用总结
性感素数(Acwing每日一题)