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

单页面企业网站最近发生的重大新闻

单页面企业网站,最近发生的重大新闻,乐清做网站的公司有哪些,wordpress 酒店日历目录 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.ritt.cn/news/8287.html

相关文章:

  • 麓谷做网站的公司seo整站排名
  • 深圳商城网站制作公司网络营销渠道类型有哪些
  • 设计师作品集网站搜狐财经峰会直播
  • 手机软件开发和网站开发最新小组排名
  • 做本地网站怎么挣钱google搜索排名优化
  • 响应式网站广州网站建设合肥网络公司
  • 网站建设 seo商情网竞价如何屏蔽恶意点击
  • 如何才能找到靠谱的网站建设公司网络营销带来的效果
  • 设计电子商务网站方式苏州市网站
  • 如何做电视剧的短视频网站如何让别人在百度上搜到自己公司
  • 越秀区做网站怎么网络推广
  • 专业建站公司报价单新网站百度收录要几天
  • 怎么做内网网站seo难不难
  • 预约做家庭清洁的网站20条优化措施
  • 网站设计案例百度认证证书
  • 昆明做网站做的好的公司有哪些软件外包公司排行
  • 小店网站怎么做荥阳网站优化公司
  • 免费的html代码模板广州网站优化价格
  • 前端课程网站站长工具seo综合查询分析
  • 谷歌云可以做网站吗福州seo技术培训
  • 海外独立站建站厦门关键词排名seo
  • 唐山网站建设推广app接单网
  • 中宁网站建设站长之家ip地址查询
  • 企业内部网页设计360优化大师
  • 深圳 网站制作百度推广营销怎么做
  • 怎么获取网站数据做统计数据营销策划有限公司经营范围
  • 新时代文明实践站网址去哪里找需要推广的app
  • 资溪做面包招聘的网站百度如何搜索网址
  • 网站搜索排名优化国家免费技能培训
  • java 政府网站开发成都公司建站模板