笛卡尔积sql语句使用方式


笛卡尔积(cross join)

--1.笛卡尔积方式一
select 
a.id,
b.code,
c.name,
d.addr
from 表1 a
cross join 表2 b
cross join 表3 c
left join 表4 e on d.id = a.id and d.code=b.code and d.name=c.name 
where a.system_type=1 
and b.system_type=2 
and c.system_type=3 
order by b.department_id


--1.笛卡尔积方式二
select 
a.id,
b.code,
c.name,
d.addr
from 表1 a
inner join 表2 b on b.system_type=2
inner join 表3 c on c.system_type=3
left join 表4 e on d.id = a.id and d.code=b.code and d.name=c.name 
where a.system_type=1 
order by b.department_id

以上2中方式都可以。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM