非顺序SQL分区

时间:2015-05-01 19:17:52

标签: sql sql-server sql-server-2012 partitioning

  

块引用

所有

我正在尝试对一组数据进行分区,但我不希望我的分区是"顺序"。

传统上,通过ID进行分区,然后按销售阶段进行分区。顺序分区。

ROW_NUMBER() OVER(PARTITION BY  ID,  sale stage ORDER BY  Converge, modified date desc)

ID               sale stage      modified date      partition
01_AAI_73133    Closed Lost        5/1/2015             1
01_AAI_73133    Closed Lost        4/26/2015            2
01_AAI_73133    Closed Lost        4/20/2015            3
01_AAI_73133    Locked and Loaded  4/5/2015             1
01_AAI_73133    Locked and Loaded  3/29/2015            2
01_AAI_73133    Pitching           3/7/2015             1
01_AAI_73133    Pitching           2/14/2015            2
01_AAI_73133    Pitching           2/1/2015             3
01_AAI_73134    Pitching           1/20/2015            4

我真正想要的是这个

ID               sale stage      modified date      partition
01_AAI_73133    Closed Lost        5/1/2015             1
01_AAI_73133    Closed Lost        4/26/2015            1
01_AAI_73133    Closed Lost        4/20/2015            1
01_AAI_73133    Locked and Loaded  4/5/2015             2
01_AAI_73133    Locked and Loaded  3/29/2015            2
01_AAI_73133    Pitching           3/7/2015             3
01_AAI_73133    Pitching           2/14/2015            3
01_AAI_73133    Pitching           2/1/2015             3
01_AAI_73134    Pitching           1/20/2015            3

有没有人知道如何实现这个目标?

由于

0 个答案:

没有答案