Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Query Question

Posted on 2016-07-28
3
Medium Priority
?
45 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

618 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