0
0
MySQLquery~20 mins

ABS and MOD in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ABS and MOD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of ABS and MOD with positive numbers
What is the output of the following MySQL query?

SELECT ABS(7), MOD(7, 3);
MySQL
SELECT ABS(7), MOD(7, 3);
A-7, 1
B7, 0
C7, 1
D-7, 0
Attempts:
2 left
💡 Hint
ABS returns the positive value of a number. MOD returns the remainder of division.
query_result
intermediate
2:00remaining
Output of ABS and MOD with negative numbers
What is the output of this MySQL query?

SELECT ABS(-10), MOD(-10, 4);
MySQL
SELECT ABS(-10), MOD(-10, 4);
A-10, 2
B10, 2
C10, -2
D-10, -2
Attempts:
2 left
💡 Hint
ABS makes numbers positive. MOD returns remainder, always non-negative in MySQL when divisor is positive.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in MOD usage
Which option contains a syntax error in using the MOD function in MySQL?
ASELECT MOD(10);
BSELECT MOD('10', 3);
CSELECT MOD(10, 3);
DSELECT MOD(-10, 3);
Attempts:
2 left
💡 Hint
MOD requires exactly two arguments.
optimization
advanced
2:00remaining
Optimizing ABS and MOD in a WHERE clause
Which query is the most efficient to find rows where the absolute value of column 'score' modulo 5 equals 3?
ASELECT * FROM results WHERE MOD(score, 5) = 3 OR MOD(score, 5) = -3;
BSELECT * FROM results WHERE ABS(MOD(score, 5)) = 3;
CSELECT * FROM results WHERE MOD(ABS(score), 5) = 3;
DSELECT * FROM results WHERE MOD(score, 5) = 3;
Attempts:
2 left
💡 Hint
MOD in MySQL always returns a non-negative remainder when divisor is positive.
🧠 Conceptual
expert
2:00remaining
Understanding MOD behavior with negative divisor
What is the output of this MySQL query?

SELECT MOD(10, -3), MOD(-10, -3);
MySQL
SELECT MOD(10, -3), MOD(-10, -3);
A-2, -1
B1, 1
C1, -1
D2, 1
Attempts:
2 left
💡 Hint
MOD returns remainder with sign of divisor in MySQL.