sql lite获取行号并为每个组重置

时间:2018-10-05 06:32:18

标签: sqlite row-number

已经搜索了该主题,并获得了线程并尝试将其修改为我所需要的,但结果以失败告终。

通过此链接 Getting row number for query

我尝试重置每个组的行号...

示例: LetterNumber | DateLetter | ToLetter | Row AA-010-2018 | 2018-09-01 | Jon | 1 AA-010-2018 | 2018-09-01 | Dian | 2 AA-010-2018 | 2018-09-01 | Jajang | 3 BB-011-2018 | 2018-09-01 | Julaeha | 4 BB-011-2018 | 2018-09-01 | Endang | 5 BB-011-2018 | 2018-09-01 | Sutisna | 6

,我想这样: LetterNumber | DateLetter | ToLetter | Row AA-010-2018 | 2018-09-01 | Jon | 1 AA-010-2018 | 2018-09-01 | Dian | 2 AA-010-2018 | 2018-09-01 | Jajang | 3 BB-011-2018 | 2018-09-01 | Julaeha | 1 BB-011-2018 | 2018-09-01 | Endang | 2 BB-011-2018 | 2018-09-01 | Sutisna | 3

我如何在sql lite中实现它?

谢谢你

1 个答案:

答案 0 :(得分:2)

如果您使用的是Sqlite 3.25或更高版本,则可以使用row_number()窗口函数:

SELECT LetterNumber
     , DateLetter
     , ToLetter
     , row_number() OVER (PARTITION BY LetterNumber) AS Row
FROM your_table
ORDER BY LetterNumber;