?
Solved

SQL Query Question

Posted on 2016-07-28
3
Medium Priority
?
43 Views
Last Modified: 2016-07-28
Select custid, (custid % 3+1) as Value
From Sales.Customers


What does the (custid % 3+1) do?

The results of the query is:

Custid     Value
1               2
2               3
3               1
4               2
5               3
6               1
7               2
8               3
9               1
11             3
0
Comment
Question by:isames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41733124
0
 
LVL 16

Accepted Solution

by:
Brian Pringle earned 1000 total points
ID: 41733131
Think back to elementary school when you had to do division and leave a remainder.  That causes it to take the customer ID, divide by 3 and find the remainder.  Then, it adds 1 to the remainder.

1 / 3 = 0 R1 --> so the result would be 1 + 1 = 2
2 / 3 = 0 R2 --> so the result would be 2 + 1 = 3
11 / 3 = 3 R2 --> so the result would be 2 + 1 = 3
0
 
LVL 6

Assisted Solution

by:Manju
Manju earned 1000 total points
ID: 41733138
Yes, second Brian.

(custid % 3+1)

Custid     Value
1               2
2               3
3               1
4               2
11            3

if custid is 4, your query will do (4/3), leaving the reminder to add 1, so result is 2.

(11 % 3 + 1) = (11/3) = 3*3 = 9, so remainder is 2 (+1) = 3
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question