当前位置:网站首页>Mysql题目篇
Mysql题目篇
2022-06-24 12:54:00 【CV工程师呀】
1.增
1.1为表中指定字段添加数据
INSERT INTO 表名(字段名1,字段名2,…)VALUES(值1,值2,…)
INSERT INTO `user`(id,role) VALUES(3,"admin");
1.2为表中所有字段添加数据(可以不指名字段)
INSERT INTO 表名 VALUES(值11,值2,…);
INSERT INTO `user` VALUES(5,"lsy","lsy1234","admin");
1.3同时添加多条数据
INSERT INTO `user` VALUES(6,"lsy","lsy1234","admin"),
(7,"lsy7","lsy1234","admin"),
(8,"lsy8","lsy1234","admin");
2.删
2.1删除部分数据
DELETE from user where username="lsy"
2.2删除所有数据
DELETE from user
3.改
3.1修改部分数据
UPDATE user set role="admin1" where id=9
3.2修改全部数据
UPDATE user set role="admin2"
4.查
4.1简单查询
select id,role from user
select * from user
select id,role from user where id<10
select id,role from user where id in (9,10)
select id,role from user where id BETWEEN 2 and 10
select id,role from user where role is NULL
select id,role from user where role like "adm%"(%匹配任意长度的字符串,包括空字符串。)
select id,role from user where role like "adm_"(下划线通配符只匹配单个字符)
select id,role from user where role like "admi_" and username="shiro"(AND 的优先级高于 OR)
select id,role from user where role like "admi_" or username="shiro"
4.2高级查询
SELECT COUNT(*) FROM user
SELECT sum(id) FROM user
SELECT avg(id) FROM user
SELECT max(id) FROM user
SELECT min(id) FROM user
SELECT *from user order by id DESC
SELECT COUNT(*) ,gender FROM user GROUP BY gender;
SELECT sum(grade),gender FROM user GROUP BY gender HAVING SUM(grade) < 300;
SELECT * from user LIMIT 2
4.3子查询
SELECT * FROM user where id=(SELECT MAX(id) from user)
SELECT * FROM (SELECT MAX(id) from user) as user1
4.4表连接
SELECT * FROM user u INNER JOIN role r on u.id=r.id
SELECT * FROM user u LEFT JOIN role r on u.id=r.id
SELECT * FROM user u RIGHT JOIN role r on u.id=r.id
SELECT * FROM user u LEFT JOIN role r on u.id=r.id UNION SELECT * FROM user u RIGHT JOIN role r on u.id=r.id
边栏推荐
- #yyds干货盘点# 解决剑指offer:调整数组顺序使奇数位于偶数前面(二)
- CPU status information us, sy and other meanings
- These default routes and static routes can not be configured and deployed. What kind of network workers are they!
- kotlin 协程 lanch 详解
- 3. Caller 服务调用 - dapr
- Integrated API interface code of domestic express companies for intra city distribution and ordering - Express 100
- Kotlin keyword extension function
- 【sdx62】WCN685X IPA不生效问题分析及解决方案
- 问个sql view的问题
- ERR AUTH&lt; password&gt; called without anypassword configured for the default user. Ar
猜你喜欢

硬件开发笔记(六): 硬件开发基本流程,制作一个USB转RS232的模块(五):创建USB封装库并关联原理图元器件

Kubernetes cluster deployment

Who is the fish and who is the bait? Summary of honeypot recognition methods from the perspective of red team

Huawei PC grows against the trend, and product power determines everything

Vulnerability management mistakes that CIOs still make

Seven challenges faced by data scientists and Solutions

‘高并发&高性能&高可用服务程序’编写及运维指南

Eight major trends in the industrial Internet of things (iiot)

Sinomeni vine was selected as the "typical solution for digital technology integration and innovative application in 2021" of the network security center of the Ministry of industry and information te

These default routes and static routes can not be configured and deployed. What kind of network workers are they!
随机推荐
华为 PC 逆势增长,产品力决定一切
What is the difference between sap QM and UD for inspection lots with hum?
敏捷之道 | 敏捷开发真的过时了么?
Understanding openstack network
Preparation and operation & Maintenance Guide for 'high concurrency & high performance & high availability service program'
Detailed explanation of kotlin collaboration lanch
金鱼哥RHCA回忆录:DO447管理清单和凭据--为访问清单主机创建机器凭据
硬件开发笔记(六): 硬件开发基本流程,制作一个USB转RS232的模块(五):创建USB封装库并关联原理图元器件
CVPR 2022 | interprétation de certains documents de l'équipe technique de meituan
如何化解35岁危机?华为云数据库首席架构师20年技术经验分享
TCP triple handshake
Kotlin language features
Developer survey: rust/postgresql is the most popular, and PHP salary is low
Goldfish rhca memoirs: do447 managing projects and conducting operations -- creating a project for ansible scripts
Definition and use of constants in C language
Troubleshooting the kubernetes problem: deleting the rancher's namespace by mistake causes the node to be emptied
Sphere, openai and ai21 jointly publish the best practice guidelines for deployment models
Vulnerability management mistakes that CIOs still make
Liux command
一文讲透研发效能!您关心的问题都在