SQLite Forum

Novice question concerning adding conditional incremental integer counter
Login
Hello, would you please tell me if it is possible in SQLite to add a new index_no column to this data that counts each row, skipping rows with strongs_no of 'punc2'?
I can add a new column and update it in a Tcl script or C code, but don't know how to start a counter in plain SQL or have it restart at 1 at each change in book, chapter, verse. By that I mean, when book_no=1 and chapter_no=1 and verse_no=3, the new index_no needs to start at 1 again and increment until verse_no 4 is reached.

I don't want to eliminate the 'punc2' rows, but just want another index_no that starts at 1 and increments sequentially ignoring all 'punc2' rows.  The purpose is to attempt to use the combination of book, chapter, verse, index to join with two other sources in place of the desired match column which is Hebrew and which I cannot get to work properly even after unicode normalization on all source tables. 

At this point, I don't need to add a new column to the table, but would like to use a CTE to see if the sources will match properly, but I'm completely stumped as to how to get a value in a select statement that can be incremented.  I've looked at recursion in a with statement but don't see how to restart the counter when move to a new verse.

Thank you for any guidance you may be able to provide.


book_no  chapter_no  verse_no  index_no  strongs_no      desired new index
-------  ----------  --------  --------  ----------      -----------------
1        1           2         1         H776                   1
1        1           2         2         H1961                  2
1        1           2         3         H8414                  3
1        1           2         4         punc2              
1        1           2         5         H922                   4
1        1           2         6         punc2       
1        1           2         7         H2822                  5
1        1           2         8         H5921                  6
1        1           2         9         H6440                  7
1        1           2         10        H8415                  8
1        1           2         11        punc2   
1        1           2         12        H7307                  9
1        1           2         13        H430                  10
1        1           2         14        H7363                 11
1        1           2         15        H5921                 12
1        1           2         16        H6440                 13
1        1           2         17        H4325                 14
1        1           2         18        punc2    
1        1           3          1        H430                   1