Mod negative numbers in SQL just like excel

This will give a result between 0 and n – 1 for both positive and negative values of x:

((x % n) + n) % n

Leave a Comment