Hive 配置单元sql将记录计数添加为列
我有类似以下的记录Hive 配置单元sql将记录计数添加为列,hive,hiveql,Hive,Hiveql,我有类似以下的记录 fruit day apple 1/1/1990 apple 1/2/1990 apple 1/3/1990 plum 1/1/1990 orange 1/1/1990 orange 1/2/1990 orange 1/3/1990 我想保持每天项目的运行总数,假设项目每天增加1。比如说 fruit day count apple 1/1/1990
fruit day
apple 1/1/1990
apple 1/2/1990
apple 1/3/1990
plum 1/1/1990
orange 1/1/1990
orange 1/2/1990
orange 1/3/1990
我想保持每天项目的运行总数,假设项目每天增加1。比如说
fruit day count
apple 1/1/1990 1
apple 1/2/1990 2
apple 1/3/1990 3
plum 1/1/1990 1
orange 1/1/1990 1
orange 1/2/1990 2
您可以使用窗口计数:
您还可以使用子查询:
@VamsiPrabhala计数可以按顺序打开窗口。请检查提供的演示
SELECT *, COUNT(*) OVER(PARTITION BY fruit ORDER BY day)
FROM tab;
select *,
(select count(*) from table where fruit = t.fruit and day <= t.day) count
from table t;