我有一个Hive产品与评级。
Id, productid, rating, ProdBarCode
42 96 5 881107178
168 151 5 884288058
110 307 4 886987260
58 144 4 884304936
62 21 3 879373460
279 832 3 881375854
237 514 4 879376641
我想写一个查询查找平均产品评级的产品,以管道分隔的文本文件头使用 hive -e"query" > output.txt
输出format:- |Productid|average rating|
解决方案: hive -e " select C.value from (select 1 key, '|Productid|average rating|' value union all select 2 key , concat('|',concat_ws('|', Productid, averagerating),'|') value from (select CAST(A.productid AS STRING) AS Productid, CAST(A.averagerating AS STRING) AS averagerating from (select productid, avg(rating) averagerating from product group by productid sort by productid ) AS A where A.averagerating > 2) B sort by key) C " > output.txt
这个问题正确吗?有没有其他简单的方法来重定向标题和列名有空格(平均评级)的文本文件中的输出?
有什么建议吗
暂无答案!
目前还没有任何答案,快来回答吧!