笛卡爾積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