4. Identify the error in this query: SELECT CEIL(5.7, 1), FLOOR(3.2), ROUND(2.718);
medium
A. ROUND requires two arguments
B. FLOOR requires two arguments
C. CEIL does not accept two arguments
D. No error, query is correct
Solution
Step 1: Check CEIL function arguments
CEIL only accepts one argument (the number). Passing two arguments causes an error.
Step 2: Verify FLOOR and ROUND usage
FLOOR accepts one argument, ROUND can accept one or two arguments. Both FLOOR(3.2) and ROUND(2.718) are valid.
Final Answer:
CEIL does not accept two arguments -> Option C
Quick Check:
CEIL = 1 argument only [OK]
Hint: CEIL/FLOOR take 1 argument; ROUND can take 1 or 2 [OK]
Common Mistakes:
Passing two arguments to CEIL or FLOOR
Assuming ROUND always needs two arguments
Thinking query has no errors
5. You have a table prices with a column cost containing decimal values. You want to create a new column rounded_cost that rounds cost to the nearest integer but always rounds up if the decimal part is exactly 0.5. Which MySQL expression achieves this?
hard
A. ROUND(cost)
B. IF(cost - FLOOR(cost) = 0.5, FLOOR(cost), ROUND(cost))
C. CEIL(cost - 0.5)
D. CEIL(cost)
Solution
Step 1: Understand rounding rules
In MySQL, ROUND rounds to nearest integer; halfway cases (.5) round away from zero (up for positive numbers).
Step 2: Select the correct expression
CEIL(cost) always rounds up, so it rounds up when decimal part is exactly 0.5, fulfilling the requirement.
Step 3: Analyze other options
A rounds .5 up normally, but does not always round up if decimal is exactly 0.5 (it rounds to nearest). B rounds down for exactly .5, which is incorrect. D fails on .5 cases as CEIL(cost - 0.5) can round down.
Final Answer:
CEIL(cost) -> Option D
Quick Check:
CEIL(cost) always rounds up [OK]
Hint: CEIL(cost) always rounds up, including .5 cases [OK]
Common Mistakes:
Assuming ROUND always rounds .5 up as needed
Using conditional that rounds .5 down
CEIL(cost - 0.5) fails on .5 cases
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.