What does % in this WHERE clause do?

598    Asked by EmmaLewis in SQL Server , Asked on Sep 9, 2021
I'm doing training and one of the scripts has the following command: SELECT SUM(Col2) FROM clust_table WHERE Col1 % 3 = 1
I would like to know what this snippet is for in the WHERE clause: Col1 % 3 = 1

I did some research on the internet and found no references about this command.

Answered by Elvera Peasley

It is being used as a Modulo Operator; returning the remainder of a number divided by another to solve sql server modulo. In your example, the WHERE clause is limiting the results to only those where the Col1 value divided by 3 leaves a remainder of 1. (e.g. 4,7,10, etc.) Hope this help you solve sql server modulo error efficiently!



Your Answer

Interviews

Parent Categories