3.14

join 也可以写成inner join
# join的链接,找到两张表中 共有的数据
# left join ,左连接,以左表为主,左表的全部数据都保留,右表的数据,有就显示,没有就是显示null
# right join 右连接,以右表为主,右表的全部数据都保留,左表的数据,有就显示,没有就是显示null
select s.*,sc.*
from stu as s
right join score as sc on s.id = sc.id;
select s.*,sc.*
from score as sc
left join stu as s on s.id = sc.id;

 

join 内连接: 找两张表中,共有的数据
left join 左外连接/左连接 :除了共有的数据之外,还要左表的数据
right join 右外连接/右连接 :除了共有的数据之外,还要右表的数据
1、找关系
2、有没有那张表的数据全部都要。

 

# 视图(虚拟的表) 可以查询,如果原来的查询结果发生改变,视图会自动改变
create or replace view 视图名称 as 查询语句;
create or replace view deptsal as
select deptno,avg(sal) as d_sal from emp group by deptno;
update emp set sal=sal+10000 where deptno=10; # 如果原来的查询结果发生改变,视图会自动改变
select * from deptsal;
drop view deptsal; # 删除视图

 

# 视图(虚拟的表) 可以查询,如果原来的查询结果发生改变,视图会自动改变
create or replace view 视图名称 as 查询语句;
create or replace view deptsal as
select deptno,avg(sal) as d_sal from emp group by deptno;
update emp set sal=sal+10000 where deptno=10; # 如果原来的查询结果发生改变,视图会自动改变
select * from deptsal;
drop view deptsal; # 删除视图
# 索引 index 表 >>> 书 , 索引 >>> 书的目录,提升查找的效率,降低增删改的效率
select count(*) from test; # 9999999
SELECT * FROM test where id =8999999;
create unique index 索引名称 on 表(列); # 给表的某一列 增加索引
create unique index tidx on test(id);
drop index 索引名称 on 表名; # 删除索引
drop index tidx on test;

 

posted @ 2023-03-15 15:21  阿凡快醒醒  阅读(117)  评论(0)    收藏  举报