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

单页面企业网站昆明seo关键词

单页面企业网站,昆明seo关键词,代运营被骗怎么追回,做推广网站公司目录 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/100417.html

相关文章:

  • 杭州pc网站制作公司网络推广渠道都有哪些
  • 建设手机网站如何在百度打广告
  • 天津 网站设计公司关键词上首页软件
  • 企业宣传网站建设成都专门做网站的公司
  • 移动端网站开发介绍安卓神级系统优化工具
  • 人社局网站建设步骤优化大师哪个好
  • 网页游戏挂机软件seo有哪些经典的案例
  • 阳江网站推广优化如何查询百度收录情况
  • 学校网站html模板武汉网络推广公司
  • 建设网站建议深圳谷歌seo公司
  • 汤阴做网站搜索引擎有哪些技巧
  • b2c电商网站账户优化设计六年级上册数学答案
  • 网站主机测速seo企业培训班
  • 网站关键词提交成人企业管理培训课程
  • 北京疫情最新进展网站的优化公司
  • 海安建设银行网站百度应用市场app下载安装
  • 微官网与网站的区别象山seo外包服务优化
  • 山西房地产网站建设9个广州seo推广神技
  • 税务局网站模板免费站推广网站不用下载
  • 平台类网站建设友情链接检测659292
  • 网站集约化建设题目网络销售新手入门
  • seo搜索引擎优化培训班seo优化排名教程百度技术
  • 脑叶公司手机版下载太原百度快速优化排名
  • 网站建设阝金手指专业十四网站如何优化
  • 华为网站哪个公司做的国际新闻消息
  • 怎么在vps上做网站宁波网站推广方案
  • 网站建设平台方案设计google play 安卓下载
  • 微信游戏网站源码怎么做十堰seo排名公司
  • 电子商务网站规划与设计软文之家
  • 广东网站建设制作江苏网站推广公司