在Hiveql中,SemanticException [错误10004]:第1行:126无效的表别名或列引用'timesheet':(可能的列名是:author)

时间:2018-04-08 19:11:32

标签: hive hiveql

我的查询是在

之后
select drivers.Author 
from timesheet 
join drivers 
on drivers.BibNum = timesheet.BibNum
group by drivers.Author 
order by count(timesheet.BibNum) desc
limit 1;

但我收到了这个错误,

  

编译语句时出错:FAILED:SemanticException [错误10004]:第1行:126无效的表别名或列引用'timesheet':(可能的列名是:author)

我的表格看起来像这样

驱动

+-----------------+-----------------+-----------------+--+
| bibnum          | string          | from deserializer |
| title           | string          | from deserializer |
| author          | string          | from deserializer |
| isbn            | string          | from deserializer |
| publicationyear | string          | from deserializer |
| publisher       | string          | from deserializer |
| subjects        | string          | from deserializer |
| itemtype        | string          | from deserializer |
| itemcollection  | string          | from deserializer |
| floatingitem    | string          | from deserializer |
| itemlocation    | string          | from deserializer |
| reportdate      | string          | from deserializer |
| itemcount       | string          | from deserializer |
+-----------------+-----------------+-----------------+--+

时间表

+-----------------+-----------------+-----------------+--+
| bibnum          | string          | from deserializer |
| itembarcode     | string          | from deserializer |
| itemtype        | string          | from deserializer |
| itemcollection  | string          | from deserializer |
| callnumber      | string          | from deserializer |
| checkoutdatetime | string          | from deserializer |
+-----------------+-----------------+-----------------+--+

如果你知道原因,请赐教,谢谢你的帮助。 如果您需要有关架构的更多信息,请与我们联系。

2 个答案:

答案 0 :(得分:1)

错误在于order by。只有select个ed列可以进入。更改查询以删除order by。或者将count添加到select并将其用于订购。

select drivers.Author,count(timesheet.BibNum) as cnt 
from timesheet 
join drivers on drivers.BibNum = timesheet.BibNum
group by drivers.Author 
order by cnt 

答案 1 :(得分:1)

通过bibnum加入两个表,然后按照aurhor名称加入。最受欢迎的作者将拥有最多的读者,因此按降序排列。限制1只会获得最高记录。

编辑:使用HIVE而不是mysql

SELECT tab.Author
from (
SELECT t2.Author, 
      count(t1.Bibnum) as cnt
FROM  timesheet t1
INNER JOIN drivers t2 on trim( t1.BibNum) = trim(t2.Bibnum)
WHERE LENGTH(trim(t2.Author)) > 0
GROUP BY t2.Author
ORDER BY cnt DESC 
LIMIT 1) tab;