当前位置:网站首页>MySQL notes under
MySQL notes under
2022-07-31 00:23:00 【web15286201346】
目录
分组查询后规定条件: HAVING 筛选分组查询结果里面的条件
本文是本人以前笔记,如果说是在掘金上看到的话没错,还是本人程程呀 的个人主页 - 动态 - 掘金只有这一个.如果有哪里不对的话欢迎各位大佬指出问题,本人是一个小白.
上一篇文章链接为:MySQL笔记上_的博客-CSDN博客,本篇是下.
如果是springboot的话请看springboot创建项目_的博客-CSDN博客,这个是从头开始的还没有学完springboot,一起学习呀!!!!
#学生信息表添加数据
#一次添加一条数据
INSERT into student(stuid,stuname,stusex,studate,classid)
values(1003,"小明","女","2020-05-08",202004)
#省略into
INSERT student(stuid,stuname,stusex,studate,classid)
values(1004,"小张","女","2020-05-08",202006)
#省略列名
INSERT student VALUES(1006,"小花","女","2020-05-08",202007)
#一次添加多条数据
INSERT student VALUES
(1007,"小李","女","2020-05-08",202008),
(1008,"小苏","女","2020-05-08",202009),
(1009,"小周","女","2020-05-08",202010)
#有约束的列添加信息
#添加calss班级表信息
INSERT class VALUES(4,"网络六班","2021-05-08 13:56:17",NULL,remark,3)
修改一条
update?表名 set 字段1=值1?where?条件
#修改数据
#修改单条数据
#根据学生编号主键修改学生信息
update student set Stuname="小宁",Stusex="男" WHERE Stuid=1003;
#修改多条数据
update student set classid=1,
Stusex="男"where Stuid in(1006,1007,1008)
#UPDATE student set classid=1,Stusex="男",WHERE Stuid in(1006,1007,1008)
#级联问题(主外键)
-- 有主外级关系,并且有外键约束是不可以更改
UPDATE student set classid=2022,Stusex="女"where Stuid in(1003,1006)
#:主外建级关系修改
ALTER TABLE student DROP FOREIGN key fk_classid;
– 更改班级表中的班级编号和班级名称
UPDATE calss set classid=110,classname='程程'WHERE classid=1;
#更改学生信息表中的classid=1
UPDATE student set classid=1 where classid=1;
#重新添加外键约束
ALTER TABLE student
add CONSTRAINT fk_classid FOREIGN key(classid) REFERENCES calss(classid);
删除一条
delete?from?表名?where?条件
#删除表数据
#删除一行或者一条学生信息
#根据主键删除信息
delete FROM student WHERE stuid=1004;
#remove multiple lines containingin
delete FROM studentinfo WHERE stuid in(1003,1007);
#删除用truncate效率高
truncate table studentinfo;
分组
select?字段1,字段2?from 表名 group by?字段1;
#分组查询
#1.单列查询
#group by 分组
SELECT Stusex 性别, count(Stusex) 人数 from student GROUP BY Stusex;
#2.多列分组
SELECT??classid 班级编号 ,Stusex 性别, count(Stusex) 人数 from student GROUP BY classid,Stusex;
分组查询后规定条件: HAVING 筛选分组查询结果里面的条件
SELECT??classid 班级编号 ,Stusex 性别, count(Stusex) 人数
from student
GROUP BY classid,Stusex HAVING Stusex='女';
多表链接
1.内连接查询(等值查询):两个表或者两个表以上
– 指令:inner join
– 语法:SELECT 列 from 表一 [inner] join 表二 on <表达式>
#学生信息表 和班级表 内连接查询
– 等值的部分取出来 ,If the difference is different, the table is discarded and an alias is given
SELECT s.Stuid??'学生编号', s.Stuname??'学生名称',s.Stusex '性别', s.Studate '入学时间', s.classid '班级编号(s表:外键)',
c.classid '班级编号(c表:主键)',c.classname '班级名称', c.begintime '入学时间',c.endtime '结束时间',c.remark '备注',c.gradeid
FROM student s INNER JOIN calss c on s.classid=c.classid;
2. INNER JOIN 也可以不写
SELECT s.Stuid ‘学生编号’,s.Stuname ‘学生姓名’, s.Stusex ‘学生性别’, c.classid ‘班级编号(c表:主键)’, c.classname ‘班级名称’,
c.gradeidFROM student s,calss c where s.classid=c.classid;
SELECT s.Stuid’学生编号’, s.Stuname’学生名称’,s.Stusex ‘性别’, s.Studate ‘入学时间’, s.classid ‘班级编号(s表:外键)’,
c.classid ‘班级编号(c表:主键)’,c.classname ‘班级名称’, c.begintime ‘入学时间’,c.endtime ‘结束时间’,c.remark ‘备注’,c.gradeid
FROM student s , calss c where s.classid=c.classid;
#自连接:等值匹配1,自己表中列匹配.只存在一张表中
– 表自己连接自己
SELECT??s1.classid 学生编号,s1.Stuname 学生姓名,s2.zid??组别
FROM student s1 JOIN student s2 on s1.zid=s2.Stuid;
#自连接和内连接都用inner join inner 可以不写
SELECT??s1.classid 学生编号,s1.Stuname 学生姓名,s2.zid??组别
FROM student s1 ,student s2 where s1.zid=s2.Stuid;
#3.外连接:左外连接和右外连接(两个表及以上)
– 左外连接:left join指定:不仅可以匹配到等值数据还可以匹配到左其他没有匹配到的数据
SELECT s.Stuid??'学生编号',
s.Stuname??'学生名称',
s.classid '班级编号(s表:外键)',
c.classid '班级编号(c表:主键)',
c.gradeid '班级名称(c表:外键)'
FROM student s LEFT JOIN calss c on s.classid=c.classid;
本文是本人以前笔记,如果说是在掘金上看到的话没错,还是本人程程呀 的个人主页 - 动态 - 掘金只有这一个.如果有哪里不对的话欢迎各位大佬指出问题,本人是一个小白.
如果是springboot的话请看springboot创建项目_的博客-CSDN博客,这个是从头开始的还没有学完springboot,一起学习呀!!!!
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在.深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小.自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前.因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担.添加下方名片,即可获取全套学习资料哦
边栏推荐
猜你喜欢
unity2D横版游戏教程4-物品收集以及物理材质
Summary of the stock problem of state machine dynamic programming
Android security optimization - APP reinforcement
A complete guide to avoiding pitfalls for the time-date type "yyyy-MM-dd HHmmss" in ES
How to solve types joiplay simulator does not support this game
47. 【Pointers and Arrays】
Steven Giesel 最近发布了一个由5部分内容组成的系列,记录了他首次使用 Uno Platform 构建应用程序的经验。
what is jira
【c语言课程设计】C语言校园卡管理系统
How to Repair Word File Corruption
随机推荐
消息队列存储消息数据的MySQL表设计
Shell编程之条件语句
45. [Application of list linked list]
transition transition && animation animation
Common network status codes
Game mall table establishment
Machine Learning 1-Regression Model (2)
Steven Giesel recently published a 5-part series documenting his first experience building an application with the Uno Platform.
asser利用蚁剑登录
Kotlin协程:协程上下文与上下文元素
Axure Carousel
transition过渡&&animation动画
The difference between substring and substr in MySQL
网络常用的状态码
joiplay模拟器如何调中文
47. 【Pointers and Arrays】
Understand from the 11 common examples of judging equality of packaging types in the written test: packaging types, the principle of automatic boxing and unboxing, the timing of boxing and unboxing, a
IOT cross-platform component design scheme
[In-depth and easy-to-follow FPGA learning 13---------Test case design 1]
xss绕过:prompt(1)