select (
SELECT SUM(countNumber) from(
SELECT FROM_UNIXTIME(unix_timestamp(AddTime),'yyyy-MM-dd') AS dateTime,
COUNT(productID) AS countNumber
FROM product
GROUP BY FROM_UNIXTIME(unix_timestamp(AddTime),'yyyy-MM-dd')
) as bb
where aa.dateTime >= bb.dateTime
) as totalCount,
aa.countNumber,
aa.dateTimefrom (
SELECT FROM_UNIXTIME(unix_timestamp(AddTime),'yyyy-MM-dd')AS dateTime,
COUNT(productID) AS countNumber
FROM product
GROUP BY FROM_UNIXTIME(unix_timestamp(AddTime),'yyyy-MM-dd')
) aa order by dateTime desc limit 10000;
我不想查询每日累计数量。为什么此HQL无法使用?Hive引擎提示:
FAILED: ParseException line 2:8 cannot recognize input near 'SELECT' 'SUM' '(' in expression specification
答案 0 :(得分:0)
Hive不允许将子查询作为列。要获取累计数量,请使用窗口函数sum
。
SELECT dateTime,countNumber,SUM(countNumber) OVER(order by dateTime) as cumsum
FROM (SELECT FROM_UNIXTIME(unix_timestamp(AddTime),'yyyy-MM-dd') AS dateTime,
COUNT(productID) AS countNumber
FROM product
GROUP BY FROM_UNIXTIME(unix_timestamp(AddTime),'yyyy-MM-dd')
) t