'SQLite: Subtract 1st Row from Last Row

I have a large table data that has an ascending counter the column counter for each row. Assuming that my program is working correctly, counter should increase by 20 units per row.

Therefore, for each table the query Select (Max(counter)-Min(counter))/(Max(ROWID)-1) should return 20 if the program works correctly. If the program drops any rows, the query would return > 20.

As I know that Max and Min are in rows 0 and N, is there a better way to run this search without requiring the processor to search the entire table for the max value?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source