将值传播到其他行但仍然尊重总和

Spreading the values to other rows but still respecting the total sum

我有如下数据集:

date        employee     products     sales
20210101       ben          5         laptop
20210101       ben         10         monitor
20210201       tim         15         laptop
20210301       tim         10         monitor

我想做的是再添加一个 field/column 作为这些员工的工作时间。根据员工当天的行数(最多 5-10 行),工作时间应平均分配,但总工作时间应始终为每天最多 6 小时。

所需的输出应该是:

date        employee     products     sales        hours
20210101       ben          5         laptop         3
20210101       ben         10         monitor        3
20210201       tim         15         laptop         6
20210301       tim         10         monitor        6

我不知道执行此查询有什么好主意。如果有人能给我一个解决这个问题的方法或方法的提示,我将不胜感激。

确定 redshift 支持 window 函数..

SELECT *,
  6.0/COUNT(*) OVER(PARTITION BY date, employee) as hours 
FROM dataset