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

得到:

 

posted @ 2020-09-10 15:45  PEAR2020  阅读(2342)  评论(0编辑  收藏  举报