Solved

SQL Query Question

Posted on 2016-07-28
3
31 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
3 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41733124
0
 
LVL 16

Accepted Solution

by:
Brian Pringle earned 250 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 250 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now