表格没有正确使用[错误10004]

时间:2017-02-28 17:10:43

标签: sql hive

Select count(*) cnt
from fin_sap_prd_tbls.cdhdr cdhdr
  Join fin_sap_prd_tbls.cdpos cdpos on (cdhdr.changenr = cdpos.changenr)
  Join fin_sap_prd_tbls.ekko  ekko on (ekko.lifnr = cdpos.objectid)
  Join fin_sap_prd_tbls.ekpo  ekpo on (ekpo.ebeln = ekko.ebeln)
where cdhdr.objectclas = 'KRED'
  and cdhdr.objectid = 'vendornumber'
  and cdpos.fname = 'ZTERM'
  and ekpo.elikz != 'X';


Select count(*) cnt
from fin_sap_prd_tbls.cdhdr xcdhdr
  Join fin_sap_prd_tbls.cdpos xcdpos on (xcdhdr.changenr = xcdpos.changenr)
 /* Join fin_sap_prd_tbls.ekko  xekko on (xekko.lifnr = xcdpos.objectid)*/
 /* Join fin_sap_prd_tbls.ekpo  xekpo on (xekpo.ebeln = xekko.ebeln)*/
  where xcdhdr.objectclas = 'KRED'
  and xcdhdr.objectid = 'vendornumber'
  and xcdpos.fname = 'ZTERM'
  /*and xekpo.elikz != 'X';*/

Select count(*) cnt
from /*fin_sap_prd_tbls.cdhdr xcdhdr
  Join*/ fin_sap_prd_tbls.cdpos xcdpos /*on (xcdhdr.changenr = xcdpos.changenr)*/
  Join fin_sap_prd_tbls.ekko  xekko on (xekko.lifnr = xcdpos.objectid)
 /* Join fin_sap_prd_tbls.ekpo  xekpo on (xekpo.ebeln = xekko.ebeln)*/
  where xcdhdr.objectclas = 'KRED'
  and xcdhdr.objectid = 'vendornumber'
  and xcdpos.fname = 'ZTERM'
  /*and xekpo.elikz != 'X';*/

我使用的数据库是Hive,运行此代码时出现以下错误。当我单独运行所有连接时,一切正常,并返回数据。

作为一个侧面问题我也希望'hdr'表可以有多个结果我希望它能产生最新的变化。我已经尝试了Max(),但它也出错了。

失败:SemanticException [错误10004]:第1行:10155无效的表别名或列引用'cdpos'

1 个答案:

答案 0 :(得分:0)

我会删除别名,因为表名已经与别名匹配。具有相同名称的对象可能会混淆引擎。

SELECT count(*) cnt
FROM fin_vsap_prd_tbls.cdhdr 
  JOIN fin_sap_prd_tbls.cdpos on (cdhdr.changenr = cdpos.changenr)
  JOIN fin_sap_prd_tbls.ekko  on (ekko.lifnr = cdpos.objectid)
  JOIN fin_sap_prd_tbls.ekpo  on (ekpo.ebeln = ekko.ebeln)
WHERE cdhdr.objectclas = 'KRED'
  and cdhdr.objectid = 'vendornumber'
  and cdpos.fname = 'ZTERM'
  and ekpo.elikz != 'X';

或以不同方式命名......

SELECT count(*) cnt
FROM fin_vsap_prd_tbls.cdhdr  xcdhdr
  JOIN fin_sap_prd_tbls.cdpos xcdpos on (xcdhdr.changenr = xcdpos.changenr)
  JOIN fin_sap_prd_tbls.ekko  xekko on (xekko.lifnr = xcdpos.objectid)
  JOIN fin_sap_prd_tbls.ekpo  xekpo on (xekpo.ebeln = xekko.ebeln)
WHERE xcdhdr.objectclas = 'KRED'
  and xcdhdr.objectid = 'vendornumber'
  and xcdpos.fname = 'ZTERM'
  and xekpo.elikz != 'X';