大力推广建设电子商务网站技术定制网站设计公司
大力推广建设电子商务网站技术,定制网站设计公司,html5中国网站欣赏,网站开发客户挖掘相关文章
sql 的 join、left join、full join的区别图解总结#xff0c;测试#xff0c;注意事项
1. 结论示意图 对于intersect、minus#xff0c;oracle支持#xff0c;mysql不支持#xff0c;可以变通#xff08;in或exists#xff09;实现
2.测试
2.1.创建表和数…相关文章
sql 的 join、left join、full join的区别图解总结测试注意事项
1. 结论示意图 对于intersect、minusoracle支持mysql不支持可以变通in或exists实现
2.测试
2.1.创建表和数据
-- 建表
drop table if exists student; -- oralce 不支持 if exists
create table student (id int
);
-- 造数据4条
insert into student (id) values (1);
insert into student (id) values (2);
insert into student (id) values (3);
insert into student (id) values (4);-- 查看表数据
select * from student;2.2.查询
2.2.1. A
-- A
select * from student where id in (1,2,3);2.2.1. B
-- B
select * from student where id in (2,3,4);2.2.3. intersect(A ∩ B)。交集。oracle支持mysql不支持可以变通实现
-- intersect(A ∩ B)。交集
select * from student where id in (1,2,3)
intersect
select * from student where id in (2,3,4);
-- 变通实现
select * from student where id in (1,2,3)
and id in (
select id from student where id in (2,3,4));2.2.4. minus(A - A ∩ B)。左差集。oracle支持mysql不支持可以变通实现
-- minus(A - A ∩ B)。左差集
select * from student where id in (1,2,3)
minus
select * from student where id in (2,3,4);
-- 变通实现
select * from student where id in (1,2,3)
and id not in (
select id from student where id in (2,3,4));2.2.5. minus(A - A ∩ B)。右差集。oracle支持mysql不支持可以变通实现
-- minus(A - A ∩ B)。右差集
select * from student where id in (2,3,4)
minus
select * from student where id in (1,2,3);
-- 变通实现
select * from student where id in (2,3,4)
and id not in (
select id from student where id in (1,2,3));2.2.6. union(A ∪ B)。并集去重
-- union(A ∪ B)。并集去重
select * from student where id in (1,2,3)
union
select * from student where id in (2,3,4);2.2.7. union all(A B)。和集不去重
-- union all(A B)。和集不去重
select * from student where id in (1,2,3)
union all
select * from student where id in (2,3,4);2.2.8. (A minus B) union (B minus A)[(A - B) (B - A)]或 (A union B) minus (A intersect B)[(A ∪ B) - (A ∩ B)] 。A ∩ B在A ∪ B的补集。oracle支持mysql不支持可以变通实现
-- 算法1(A minus B) union (B minus A)[(A - B) (B - A)]。A ∩ B在A ∪ B的补集。
(
select * from student where id in (1,2,3)
minus
select * from student where id in (2,3,4)
)
union
(
select * from student where id in (2,3,4)
minus
select * from student where id in (1,2,3)
);
-- 算法1变通实现
(
select * from student where id in (1,2,3)
and id not in (
select id from student where id in (2,3,4))
)
union
(
select * from student where id in (2,3,4)
and id not in (
select id from student where id in (1,2,3))
);-- 算法2(A union B) minus (A intersect B)[(A ∪ B) - (A ∩ B)]
-- (union) minus (intersect)[(A ∪ B) - (A ∩ B)]。A ∩ B在A ∪ B的补集。
(
select * from student where id in (2,3,4)
union
select * from student where id in (1,2,3)
)
minus
(
select * from student where id in (2,3,4)
intersect
select * from student where id in (1,2,3)
);
-- 算法2变通实现
select * from
(
select * from student where id in (1,2,3)
union
select * from student where id in (2,3,4)
)
where id not in
(
select id from student where id in (1,2,3)
and id in (
select id from student where id in (2,3,4))
);
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/87899.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!