patternsqlMajor
What does % in this WHERE clause do?
Viewed 0 times
thiswhatwheredoesclause
Problem
I'm doing training and one of the scripts has the following command:
I would like to know what this snippet is for in the WHERE clause:
I did some research on the internet and found no references about this command.
SELECT SUM(Col2) FROM clust_table WHERE Col1 % 3 = 1I would like to know what this snippet is for in the WHERE clause:
Col1 % 3 = 1I did some research on the internet and found no references about this command.
Solution
It is being used as a Modulo Operator; returning the remainder of a number divided by another.
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.)
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.)
Context
StackExchange Database Administrators Q#188044, answer score: 32
Revisions (0)
No revisions yet.