HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMajor

What does % in this WHERE clause do?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thiswhatwheredoesclause

Problem

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.

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.)

Context

StackExchange Database Administrators Q#188044, answer score: 32

Revisions (0)

No revisions yet.