当前位置:网站首页>数据库的增删改查
数据库的增删改查
2022-07-17 20:41:00 【蓝鲸不蓝369】
DDL

DDL操作表


DML
添加数据

修改数据

DQL查询
基础查询

drop table if exists stu;
select *from stu
create table stu(
id int,
name varchar(5),
age int,
sex varchar(5),
address varchar(10),
math double(5,2),
english double(5,2),
hire_date date
);
alter table stu add address varchar(10);
Insert INTO stu(id,name,age,sex,address,math,english,hire_date)
VALUES
(1,'马云',55,'男','杭州',66,78,'1995-09-01'),
(2,'马化腾',45,'女','深圳',98,87,'1998-09-01'),
(3,'马斯克',55,'男','香港',56,77,'2001-01-11'),
(4,'陆佰',20,'女','湖南',76,65,'1997-09-05'),
(5,'刘青',20,'男','湖北',86,NULL,'1998-09-01'),
(6,'刘德华',45,'男','香港',33,56,'1998-09-11'),
(7,'张学友',22,'女','香港',99,99,'1997-02-11'),
(8,'德玛西亚',18,'男','南京',67,76,'1994-09-02');
select name,age from stu;
select distinct address from stu;
select name ,math as 数学成绩,english as 英语成绩 from stu;
条件查询

模糊查询

drop table if exists stu;
select *from stu
create table stu(
id int,
name varchar(5),
age int,
sex varchar(5),
address varchar(10),
math double(5,2),
english double(5,2),
hire_date date
);
alter table stu add address varchar(10);
Insert INTO stu(id,name,age,sex,address,math,english,hire_date)
VALUES
(1,'马云',55,'男','杭州',66,78,'1995-09-01'),
(2,'马化腾',45,'女','深圳',98,87,'1998-09-01'),
(3,'马斯克',55,'男','香港',56,77,'2001-01-11'),
(4,'陆佰',20,'女','湖南',76,65,'1997-09-05'),
(5,'刘青',20,'男','湖北',86,NULL,'1998-09-01'),
(6,'刘德华',45,'男','香港',33,56,'1998-09-11'),
(7,'张学友',22,'女','香港',99,99,'1997-02-11'),
(8,'德玛西亚',18,'男','南京',67,76,'1994-09-02');
select name,age from stu;
select distinct address from stu;
select name ,math as 数学成绩,english as 英语成绩 from stu;
select *from stu where age>=20;
select *from stu where age>20;
select* from stu where age>20&&age<30;
select *from stu where hire_date BETWEEN '1998-01-01' and '2022-02-01';
select*from stu where age in(18,19,20);
select*from stu where english is NULL;
select*from stu where english is not null;
select*from stu where name like '马%';
select*from stu where name like'_斯%';
select*from stu where name like'%刘%';
排序查询

分组查询

-- 查询学生信息按升序排列
select *from stu order by age asc;
-- 查询学生信息按数学成绩降序排列.
select*from stu order by math desc,english desc;
select count(id) from stu;
select count(english)from stu;
select min(math) from stu;
select sum(math) from stu;
select avg(math) from stu;
select min(english) from stu;

-- 查询学生信息按升序排列
select sex,avg(math)from stu GROUP BY sex;
select sex,avg(math),count(*) from stu group by sex;
select sex,avg(math),count(*) from stu where math>70 group by sex;
select sex,avg(math),count(*) from stu where math>70 group by sex having count(*)>1;
分页查询

边栏推荐
- How to prepare for the autumn recruitment for the graduate students of the second non science class of Graduate School
- STL string output and modification
- 「津津乐道播客」#392 原汤话原食:仲夏夜,马砂、肉串儿、趿拉板儿
- [Flink] Flink will report an error if it fails to set checkpoints once. Setlerablecheckpointfailurenumber does not work
- AcWing 134. Double ended queue
- asterisk:No compatible codecs, not accepting this offer!
- [postgraduate entrance examination vocabulary training camp] day 7 - second, attract, current, collect, simple, communicate, vocation
- Use of Google browser developer tools (Master!)
- The NFT market pattern has not changed. Can okaleido set off a new round of waves?
- 2. Sum of three numbers
猜你喜欢

Okaleido或杀出NFT重围,你看好它吗?

看一看try{}catch{}

Class 3 practice

暑期rhcsa培训第一天作业

欧奈尔的RPS曲线的编制方法(陶博士原创)

国内外十大erp软件系统排名!

2022年中国AI医学影像行业概览报告

Robotics at google:laura Graesser | i-sim2real: strengthen the learning robot strategy in the close human-computer interaction cycle

NO.6浮点数的表示与运算

Uniapp Gaode map positioning function
随机推荐
【ACWing】2492. HH Necklace
[code hoof set novice village question 600] formatted input and output, using 0 to replace the completed space
Okaleido or get out of the NFT siege, are you optimistic about it?
96. Different binary search trees
分析并HOOK SSHD来劫持密码
2. Sum of three numbers
【ACWing】2521. Count colors
揭开服务网格~Istio Service Mesh神秘的面纱
How to prepare for the autumn recruitment for the graduate students of the second non science class of Graduate School
Homework for the third day of summer rhcsa training
"Technology podcast month" day 10: meta podcast: talk about Podcasting
Class 3 practice
[postgraduate entrance examination vocabulary training camp] day 6 - eventually, state, create, productivity, stimulate
No.4 bits, bytes, information storage
洛谷:P3092 [USACO13NOV]No Change G(状压+二分,独特的状态定义,不写会后悔一辈子的题)
QT use qlisview to realize QQ login history list
活动预告|Apache Doris x Apache SeaTunnel 联合 Meetup 开启报名!
NO.2汇编初步
What are the ways to realize load balancing?
谷歌浏览器开发者工具的使用(掌握!)