为什么这个子查询hiveql不起作用?

t98cgbkg  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(293)
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不能工作?配置单元引擎提示:

FAILED: ParseException line 2:8 cannot recognize input near 'SELECT' 'SUM' '(' in expression specification
dfty9e19

dfty9e191#

配置单元中不允许子查询作为列。要获取累计数量,请使用window函数 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

相关问题