Full join 和 Cross join


 

full join 一定需要 on 条件的匹配,一条匹配全部输出

cross join 是笛卡尔积,没有匹配都能输出

例子:

 

 如何用一个值 替代null?

首先cross join,每一个值都拥有了一行

with
t1 as (select avg(scores) avg_score from testscore2 )
select * from testscore2 cross join t1

 

 再筛选,

注意遇到null时,这么写

case when scores is NULL
with
t1 as (select avg(scores) avg_score from testscore2 )
select id,subject,(case when scores is NULL then avg_score else scores end)scores 
from testscore2 cross join t1

得到:

 


免责声明!

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



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