2

我想做以下事情:

Select 
username,
(select min(sub.date) from data sub where sub.username = outer.username) as firstDate,
date,
? as dateSequence
from data as outer;

我不知道要为 dateSequence 输入什么。此值应表示“日期”值在客户在数据库中的所有天数的序列中的位置(因此 firstDate 的值将为 1 等)。

有什么办法可以做到这一点吗?客户错过了日期,并且每个日期有多个条目。提前致谢。

4

1 回答 1

4
Select username,
       select min(date) over (partition by username) as firstDate,
       date,
       row_number() over (partition by username order by date) as date_sequence
from data as outer;
于 2013-06-05T21:58:42.567 回答