在 DBVis 中创建用于索引的计算列
Creating a calculated column for indexing in DBVis
我有一个 table 包含用户访问过的网站、他们的时间戳以及与之关联的用户 ID。我想创建一个列,其中包含访问网站顺序的索引,但我希望它在我转到下一个用户时重置回 1。示例:
URL | UID | Time |Index
www.google.com/ | 1234 | 2020-01-12 17:52:51 | 1
www.google.com/doodles/about | 1234 | 2020-01-12 17:53:20 | 2
www.amazon.com/ | 4321 | 2020-01-12 13:57:02 | 1
www.amazon.com/gp/bestsellers/| 4321 | 2020-01-12 13:57:18 | 2
这可能吗?
我想你想要 row_number()
:
select t.*, row_number() over (partition by uid order by time) as seqnum
from t;
partition by
处理有关将 "next user" 的计数重置为 1
的部分。
我有一个 table 包含用户访问过的网站、他们的时间戳以及与之关联的用户 ID。我想创建一个列,其中包含访问网站顺序的索引,但我希望它在我转到下一个用户时重置回 1。示例:
URL | UID | Time |Index
www.google.com/ | 1234 | 2020-01-12 17:52:51 | 1
www.google.com/doodles/about | 1234 | 2020-01-12 17:53:20 | 2
www.amazon.com/ | 4321 | 2020-01-12 13:57:02 | 1
www.amazon.com/gp/bestsellers/| 4321 | 2020-01-12 13:57:18 | 2
这可能吗?
我想你想要 row_number()
:
select t.*, row_number() over (partition by uid order by time) as seqnum
from t;
partition by
处理有关将 "next user" 的计数重置为 1
的部分。