我在Hive中有3个表Sourcetable,Mappingtable,Destinationtable。
在这里,我根据联接条件联接前两个表。但是,当尝试对第三张表执行右连接时,我遇到了问题。 “目标表”中应遵循的条件。
我提供了表关系和在outputtable中要实现的输出。 任何指导都值得赞赏。
(select a.Account as Accounts, a.customer as customers,a.productci,b.product_cr as Productcr,sum(a.cost)/sum(a.quantity) as perprice,
from sourcetable a
LEFT join mappingtable b on( a.productci = b.product_ci ) where (a.createddate >= '2018-03-01' and a.createddate < '2018-03-06')
GROUP BY a.customer,a.Account,a.productci,b.product_cr order by a.Account,a.customer) AS TEST
RIGHT JOIN destinationtable Temp on(TEST.Productcr=Temp.productgr) where temp.createddate='2018-03-05'
GROUP BY temp.customer,temp.Account,temp.productgr
表的详细信息如下所示
SOURCETABLE
Account,customer,productci,quantity,cost,Createddate
A01,S01,100,3000,120000,3/5/2018
A02,S02,140,4000,180000,3/4/2018
映射表
product_ci,product_cr,proddesc
100,4991089,Product1
140,4991090,Product2
150,4991091,Product3
120,4991092,Product4
目标表
Account,customer,productgr,volume,placeid,Createddate
A01,S01,4991089,1890000,P01,3/5/2018
A02,S02,4991090,1890001,P02,3/5/2018
A03,S03,4991091,1890002,P03,3/5/2018
A04,S04,4991092,1890003,P04,3/5/2018
A05,S05,4991093,1890004,P05,3/5/2018
输出:结果
Account,customer,productgr,volume,Perprice,placeid
A01,S01,4991089,1890000,40,P01
A02,S02,4991090,1890001,45,P02
A03,S03,4991091,1890002,285.1002865,P03
A04,S04,4991092,1890003,30,P04
A05,S05,4991093,1890004,1170.113097,P05