为什么我在Hive中查询可以得到FAILED:Invalid table别名或列引用‘’:(可能的列名是:line)?

Why can I get the FAILED:Invalid table alias or column reference ‘ ’: (possible column names are: line) when I queried in Hive?

我有一个 table 结构是:

line      string

内容为:

product_id product_date orderattribute1 orderattribute2 orderattribute3     orderattribute4 ciiquantity ordquantity price
1 2014-09 2 1 1 1 1 3 153
1 2014-01 2 1 1 1 1 1 153
1 2014-04 2 2 1 1 1 1 164
1 2014-02 2 1 1 1 3 4 162
1 2014-07 2 1 1 1 9 23 224
1 2014-08 2 1 1 1 1 7 216
1 2014-03 2 1 1 1 3 13 180
1 2014-08 2 2 1 1 4 6 171
1 2014-05 2 1 1 1 3 7 180
....
(19000 lines omited)

以上每件line的总价为订单数量*价格

我想像这样得到每个month的总价:

month   sum
201401  ****
201402  ****

根据上面table中的10行,201408月的总和为7*216+6*171,由(1 2014-08 2 1 1 1 1 7 216 and 1 2014-08 2 1 1 1 1 7 216).

我使用代码:

create table product as select sum(ordquantity*price) as sum from text3 group by product_date;

我失败了:

FAILED:Invalid table alias or column reference 'product_date': (possible column names are: line) 

对Hive不熟悉,不知道怎么解决

您是否刚刚使用正确的架构创建了 table?以防万一,如果你没有

CREATE TABLE product
(product_id INT 
product_date STRING
orderattribute1 INT
orderattribute2 INT
orderattribute3 INT
orderattribute4 INT
ciiquantity INT
ordquantity INT
price INT)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';

以及您要求的代码,

SELECT product_date, SUM(ordquantity*price) FROM product
GROUP BY product_date;

希望我回答了你的问题。 Yippee!!