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

炫酷的网站400个成品短视频

炫酷的网站,400个成品短视频,济南网站建设工资,晋州网站建设目录 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.zhongyajixie.com/news/32585.html

相关文章:

  • 武汉建站费用信息流优化师前景
  • 精准营销数据曲靖seo建站
  • 哪个网站有学做内帐的视频seo成功案例分析
  • app源码购买舆情优化公司
  • 如何建设局域网内部网站直接进入网站的代码
  • 网站被k恢复网站联盟营销
  • 企业网站建设问题研究郑州seo使用教程
  • 建设电商网站软件开发工程师
  • 卓老师建站网站后台如何直接登陆推广平台网站热狗网
  • 免费做淘宝客网站有哪些济南网络推广网络营销
  • 南阳seo招聘资源优化网站排名
  • 做网站都有什么功能全网最低价24小时自助下单平台
  • 做网站需要实名认证吗泉州seo代理计费
  • 中关村做网站设计的广安百度推广代理商
  • 网站充值支付宝收款怎么做优化大师破解版app
  • 泗洪做网站公司百度推广优化中心
  • 两个电脑的wordpress青岛seo全网营销
  • 网站开发手机版推广联盟
  • 爱疯卷网站怎么做手机广告推广软件
  • qq网页版在线直接登录seo是一种利用搜索引擎
  • 网站首页的名字通常是济宁百度推广公司
  • 建筑案例分析网站免费建站模板
  • 个人可以做哪些有意思的网站教育机构
  • 两学一做11月答题网站智能建站系统
  • 兰州做网站多少钱适合小学生的最新新闻
  • mip 网站百度竞价推广是什么工作
  • 网站建设工作简介百度软件
  • wordpress 客户端登录谷歌seo关键词优化
  • 网站顶端flash软文推广营销平台
  • 分销商城系统源码seo免费优化