当前位置: 首页 > news >正文

单页面企业网站百度联盟是什么

单页面企业网站,百度联盟是什么,软件商店安装下载2023,网站建设好怎么优化目录 1. 问题描述2. 问题复现3. 问题原因4. 问题解决 1. 问题描述 在Hive中(其他类似SQL,比如PostgreSQL可能也存在此问题),当对多张表(3张及以上)进行full join时,会存在每张表的主键都是唯一…

目录

  • 1. 问题描述
  • 2. 问题复现
  • 3. 问题原因
  • 4. 问题解决

1. 问题描述

在Hive中(其他类似SQL,比如PostgreSQL可能也存在此问题),当对多张表(3张及以上)进行full join时,会存在每张表的主键都是唯一,但当full join后,会发现主键可能有重复。

2. 问题复现

2.1. 插入数据

with   temp1 as (
select  '1' as id ,'张三' as name
union all 
select  '2' as id ,'李四' as name
union all 
select  '3' as id ,'王五' as name
),
temp2 as (
select  '1' as id ,'深圳' as city
union all 
select  '3' as id ,'北京' as city
union all 
select  '4' as id ,'上海' as city
),
temp3 as (
select  '1' as id ,'5000' as salary
union all 
select  '4' as id ,'10000' as salary
union all 
select  '5' as id ,'12000' as salary
)

2.2. 查询SQL以及问题

selectcoalesce(a.id, b.id, c.id) as id, a.name, b.city, c.salary
from temp1 as afull join temp2 as b
on a.id = b.idfull join temp3 as c
on a.id = c.id

当执行如上查询SQL时,会发现其中 id = 4 的数据有重复,如下图所示:
在这里插入图片描述

3. 问题原因

之所以会出现这样的问题,是因为是以a表为主表,但a表中只有 id 为 1、2、3 的数据,但在b表中有id为4,c表中也有id为4,此时full join时,a表会以空值和b表、c表中id为4的数据join,这样关联后的表中就会出现2条id为4的数据;

4. 问题解决

在后续的表full join时,不单单使用第一张表的主键full join(因为是full join,所以肯定会存在第一张表为null,而其他表有值的数据),而使用 coalesce 方法对所有前面已经full join了的主键进行条件关联,如下代码:
方法1:

selectcoalesce(a.id, b.id, c.id) as id, a.name, b.city, c.salary
from temp1 as afull join temp2 as b
on a.id = b.idfull join temp3 as c
on coalesce(a.id, b.id) = c.id

结果如下:
在这里插入图片描述
方法2:

select temp.id, temp.name, temp.city, c.salary
from  
(selectcoalesce(a.id, b.id) as id, a.name , b.city 
from temp1 as afull join temp2 as b
on a.id = b.id) temp
full join 
temp3 as c
on temp.id = c.id

在这里插入图片描述
方法3:

select 
temp.id 
,temp1.name
,temp2.city
,temp3.salary
from 
(select id 
from  
(select 
id
from  temp1
union all 
select 
id
from  temp2
union all 
select 
id
from  temp3
) tt
group by id
) temp 
left  join temp1  
on temp.id = temp1.id
left  join temp2  
on temp.id = temp2.id
left  join temp3 
on temp.id = temp3.id

在这里插入图片描述

http://www.mmbaike.com/news/48869.html

相关文章:

  • 网站建设到上线步骤百度广告优化师
  • 做网站代理需要办什么营业执照竞价推广账户竞价托管收费
  • 北京知名vi设计公司珠海seo快速排名
  • 做网站需要购买网站空间吗浏览器网站进入口
  • 郑州小程序定制seo推广什么意思
  • 河南省建设部省厅网站网络营销促销方案
  • 青海青海西宁网站建设seo常用分析的专业工具
  • wordpress 主题构成河源网站seo
  • 做歌厅广告在哪个网站做好建网站免费
  • 同城配送网站建设郑州seo哪家好
  • 太原网站建站模板百度网站首页入口
  • 免费网站建设平台 iis百度信息流广告平台
  • 资深的网站推广网站ip查询
  • 杭州知名的网站制作策略宁波seo关键词费用
  • 宁波网络公司做网站优化的含义
  • 衡水哪儿做网站便宜国际军事最新消息今天
  • 构建网站需要会什么中央新闻直播今天
  • 公司企业邮箱登录入口福州seo快速排名软件
  • 什么网站专门做外贸批发搜索引擎是网站吗
  • 网站建设的类型或分类做网站哪个平台好
  • 电商网站图片是谁做互联网广告销售是做什么的
  • 商业网页设计整站优化工具
  • 锦州网站建设公司武汉疫情最新情况
  • 网站建设 织梦者外链发布论坛
  • 定制网站开发费用多少手机制作网站的软件
  • 怎样做吧网站排名做上去网店运营工资一般多少
  • 绍兴做网站公司哪家好北京优化靠谱的公司
  • 做租房信息网站手机网页制作软件
  • 网站后台怎么上传图片北京百度seo排名点击器
  • 专做展厅设计网站扫描图片找原图