当前位置:网站首页>Complete collection of basic MySQL commands
Complete collection of basic MySQL commands
2022-04-21 20:36:00 【You're a cat. You can't change to eat dried fish】
-- Show all databases
show databases;
-- Use xxx database
use xxx;
-- establish db_1 database
create databases [if not exists] db_1[character set utf8mb4];
-- Delete db_1 database
drop database (if exists) db_1;
-- Show all tables in the database
show tables;
-- see tb_1 Table structure
desc tb_1;
-- Create table
-- comment 'a' Comment to field a, The database will save and -- Can't ;
create table table_name (
field1 datatype,
field2 datatype comment 'a',
field3 datatype
);
-- take desc Methods defined as keywords
`desc` datatype;
-- If there is tb_1 surface , Delete tb_1 surface
drop table (if exists) tb_1;
-- newly added
insert into tb_1 values(------)(------);
insert into tb_1(id) values(a)(b);
-- Inquire about
-- All columns
select * from tb_1;
-- operation , Function query
select a+b,a*b,year(a),day(a),concat(name,' classmate ') from tb_1;
-- Alias
select a b from tb_1;
-- duplicate removal
select distinct a from tb_1;
-- according to a,b Two trains to remove the weight
select distinct a,b from tb_1;
-- Sort
--asc Ascending ;desc Descending
--null Top in ascending order
select a from tb_1 order by a (asc);
SELECT a b FROM exam_result ORDER BY b DESC;
-- Sort multiple fields , The order of priority follows the order of writing
select a,b,c from tb_1 order by a,b desc,c;
--where Conditions of the query
WHERE Conditions can be expressed as , But you can't use aliases
null You can't use =,!=;
and Prior to the or
between a and b;>=a,<=b;
in(a,b,c---)---> matching () Internal value SELECT name, math FROM exam_result WHERE math IN (58, 59, 98, 99);
-- Fuzzy query :LIKE
-- % Multiple _ One
SELECT name FROM exam_result WHERE name LIKE ' Grandchildren _';
-- Paging query
select ··· from tb_name limit a,b;
select ··· from tb_name [where···][order by···] limit a,b;
-- modify
update table_name set ······
-- Delete
delete from table_name [where···][order by···]
-- null constraint
-- unique Unique constraint (null Not subject to unique constraint )
-- default Default constraint
CREATE TABLE student (
id INT NOT NULL primary key,
sn INT UNIQUE,
name VARCHAR(20) DEFAULT 'unkown',
qq_mail VARCHAR(20)
);
--primary key Primary key constraint
primary key = not null & unique
-- froeign key Foreign key constraints
foreign key ( Field name ) references Main table ( Column )
CREATE TABLE classes (
id INT PRIMARY KEY auto_increment,
name VARCHAR(20),
`desc` VARCHAR(100)
);
CREATE TABLE student (
id INT PRIMARY KEY auto_increment,
sn INT UNIQUE,
name VARCHAR(20) DEFAULT 'unkown',
qq_mail VARCHAR(20),
classes_id int,
FOREIGN KEY (classes_id) REFERENCES classes(id)
);
-- Copy table
insert into table(a,b)select c,d from table;
-- function
COUNT([DISTINCT] expr) Returns the of the queried data Number SUM([DISTINCT] expr) Returns the of the queried data The sum of the , It's not that numbers don't make sense AVG([DISTINCT] expr) Returns the of the queried data Average , It's not that numbers don't make sense MAX([DISTINCT] expr) Returns the of the queried data Maximum , It's not that numbers don't make sense MIN([DISTINCT] expr) Returns the of the queried data minimum value , It's not that numbers don't make sense
count( A field )=count(*)=count( Constant )
--group by grouping
-- select column1 [, sum(column2), ..] from table group by column1 [,column3];
SELECT The specified field must be “ Group by field ”, If you want other fields to appear in SELECT Must be included in the aggregate function
-- having
GROUP BY After the clauses are grouped , When the grouping results need to be conditionally filtered , Out of commission WHERE sentence , You need to use HAVING
select role,max(salary),min(salary),avg(salary) from emp group by rolehaving avg(salary)<1500;
版权声明
本文为[You're a cat. You can't change to eat dried fish]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212030477725.html
边栏推荐
猜你喜欢

getchar,putchar,EOF

上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花板
![[Hetai ht32 communicates with STM32 through serial port and lights up]](/img/77/750edf9608d8661856afbd43449690.png)
[Hetai ht32 communicates with STM32 through serial port and lights up]

3D 沙盒游戏之人物的点击行走移动

Pytorch框架 || torch.nn.modules.Module(nn.Module)
![[daily leetcoding challenge14] a group of K flip linked lists](/img/d8/1479d52ac3ced3071db789cc2158ae.png)
[daily leetcoding challenge14] a group of K flip linked lists
![[high concurrency] analysis of thread pool and ThreadPoolExecutor class](/img/9c/ccd119193ffb9b82bf08cedb38fd0b.jpg)
[high concurrency] analysis of thread pool and ThreadPoolExecutor class

实战 | 基于JMeter 完成典型电商场景(首页浏览)的性能压测

制造业数字化转型后发展的未来画像

88%工业人都不知,小程序这7点,能让营收暴增,粗暴有效!强烈建议收藏,反复读!
随机推荐
Win11 efficient calendar recommendation
leetcode - 329. 矩阵中的最长递增路径
RTMP(4):User Control Message
VS2019配置opencv4
制造业数字化转型后发展的未来画像
实战 | 基于JMeter 完成典型电商场景(首页浏览)的性能压测
88%工业人都不知,小程序这7点,能让营收暴增,粗暴有效!强烈建议收藏,反复读!
RTMP(3):Protocol Control Message
在IE和Edge中用JS判断只能输入数字,字母,日期型。
LeetCode_70 爬楼梯
Collection of knowledge points
Andorid --- 为什么要使用事务,什么叫做事务的提交和回滚?
IaaS,PaaS,SaaS 的区别
Man machine verification reCAPTCHA V3 complete instructions
Redis Foundation
Mysql刷题题解_多表联查_运营想要计算一些参加了答题的不同学校、不同难度的用户平均答题量,请你写SQL取出相应数据
Mysql 基础命令大全
[Hetai ht32 communicates with STM32 through serial port and lights up]
Actual combat | UI automation test framework design and pageobject transformation
Jmeter如何设置参数化