Challenge - 5 Problems
ABS and MOD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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);
Attempts:
2 left
💡 Hint
ABS returns the positive value of a number. MOD returns the remainder of division.
✗ Incorrect
ABS(7) returns 7 because 7 is already positive. MOD(7, 3) returns 1 because 7 divided by 3 leaves remainder 1.
❓ query_result
intermediate2: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);
Attempts:
2 left
💡 Hint
ABS makes numbers positive. MOD returns remainder, always non-negative in MySQL when divisor is positive.
✗ Incorrect
ABS(-10) returns 10. MOD(-10, 4) returns 2 because MySQL MOD returns a non-negative remainder when the divisor is positive.
📝 Syntax
advanced2:00remaining
Identify the syntax error in MOD usage
Which option contains a syntax error in using the MOD function in MySQL?
Attempts:
2 left
💡 Hint
MOD requires exactly two arguments.
✗ Incorrect
MOD function requires two arguments. Option A has only one argument, causing syntax error.
❓ optimization
advanced2: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?
Attempts:
2 left
💡 Hint
MOD in MySQL always returns a non-negative remainder when divisor is positive.
✗ Incorrect
In MySQL, MOD(score, 5) returns values from 0 to 4. So checking MOD(score, 5) = 3 is enough and most efficient.
🧠 Conceptual
expert2: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);
Attempts:
2 left
💡 Hint
MOD returns remainder with sign of divisor in MySQL.
✗ Incorrect
MOD(10, -3) returns -2 because 10 = floor(10/-3)*(-3) + (-2) i.e., floor(-3.333)=-4, -4*(-3)=12, 10-12=-2. MOD(-10, -3) returns -1 because floor(-10/-3)=floor(3.333)=3, 3*(-3)=-9, -10 - (-9)=-1.