Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Number Functions

Table of Contents

  1. Rounding Functions

  2. Absolute Value Function


1. Rounding Functions

1.1 ROUND

Task 1 – Round a number to different decimal places Write a query that:

  • Starts from the number 3.516 (aliased as original_number)

  • Rounds it to:

    • 2 decimal places (alias: round_2)
    • 1 decimal place (alias: round_1)
    • 0 decimal places (alias: round_0)

Using the ROUND() function.

💡 Suggested Answers
SELECT 
    3.516 AS original_number,
    ROUND(3.516, 2) AS round_2,
    ROUND(3.516, 1) AS round_1,
    ROUND(3.516, 0) AS round_0

2. Absolute Value Function

2.1 ABS

Task 2 – Demonstrate the ABS (absolute value) function Write a query that:

  • Shows -10 as original_number
  • Returns the absolute value of -10 as absolute_value_negative
  • Returns the absolute value of 10 as absolute_value_positive

Using the ABS() function.

💡 Suggested Answers
SELECT 
    -10 AS original_number,
    ABS(-10) AS absolute_value_negative,
    ABS(10) AS absolute_value_positive