问题描述
我想在 SQL 中创建一个数据查询,以递增地编号行组,在公共日期时间分组,并在下一个日期时间保持组号"递增,依此类推.正如我在使用 partition by 语句时所看到的那样,这些组号"不得为每个组重置.这是我的示例数据:
I would like create a data query in SQL to incrementally number groups of rows, grouped on a common datetime and keep the "group numbers" incrementing on the next datetime and so on. These "group numbers" must not reset for each group as I have seen when using the partition by statement. Here is my sample data:
我用来获得这些结果的查询是:
The query I am using to get these results is :
所以基本上,查看 RowFilter 列,我得到每个 ts_DateTime
分区的唯一 ROW 编号.我真正需要的是,对于每个 ts_DateTime
分区,RowFilter 列应该看起来像所需的结果列.
So basically, looking at the RowFilter column, I am getting a unique ROW number per ts_DateTime
partition. What I actually need is that for each ts_DateTime
partition the RowFilter column should look like the Required result column.
推荐答案
你不应该使用 ROW_NUMBER()
,
- 改用
DENSE_RANK()
- 删除
PARTITION BY
查询,
- SQLFiddle 演示
这篇关于如何在SQL中返回每个组的增量组号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!