Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Introduction to Numeric Functions | Numeric Functions
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Functions in SQL

bookIntroduction to Numeric Functions

Numeric functions in SQL are essential tools for analyzing and transforming numerical data stored in your tables. You use these functions to round values, perform mathematical calculations, and extract specific numeric information from your data. Whether you are calculating totals, adjusting prices, or preparing data for reports, numeric functions help you get accurate and meaningful results from your queries.

1234567891011
-- Use ROUND to round prices to the nearest whole number SELECT name, price, ROUND(price) AS rounded_price FROM products; -- Use CEILING to always round prices up SELECT name, price, CEILING(price) AS ceiling_price FROM products; -- Use FLOOR to always round prices down SELECT name, price, FLOOR(price) AS floor_price FROM products;
copy

You can also use numeric functions like ABS and POWER for more advanced calculations. The ABS function returns the absolute value of a number, which is useful when you need to remove any negative sign from a result. The POWER function raises a number to a specified power, allowing you to calculate exponents or squares of values as needed for your analysis.

1234567
-- Use MOD to find the remainder of stock divided by 10 SELECT name, stock, MOD(stock, 10) AS stock_remainder FROM products; -- Use SQRT to calculate the square root of the price SELECT name, price, SQRT(price) AS price_sqrt FROM products;
copy

1. Which function rounds a number up to the nearest integer?

2. What does the MOD function return?

3. Fill in the blanks to calculate the square root of the price for each product.

question mark

Which function rounds a number up to the nearest integer?

Select the correct answer

question mark

What does the MOD function return?

Select the correct answer

question-icon

Fill in the blanks to calculate the square root of the price for each product.

SELECT name, price, (price) AS price_sqrt FROM products;
Wireless Mouse|25.99|5.098039
Mechanical Keyboard|79.99|8.944272
USB-C Charger|19.50|4.415880
27-inch Monitor|229.99|15.165750
Bluetooth Headphones|59.99|7.745967
Webcam HD|39.99|6.324555
External Hard Drive 1TB|69.99|8.366600
Gaming Chair|149.99|12.247449
Laptop Stand|34.99|5.915475
Smartphone Holder|12.99|3.603883

Clique ou arraste solte itens e preencha os espaços

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 1

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you explain how the ABS and POWER functions work with examples?

What are some other useful numeric functions in SQL?

How can I use these numeric functions in more complex queries?

bookIntroduction to Numeric Functions

Deslize para mostrar o menu

Numeric functions in SQL are essential tools for analyzing and transforming numerical data stored in your tables. You use these functions to round values, perform mathematical calculations, and extract specific numeric information from your data. Whether you are calculating totals, adjusting prices, or preparing data for reports, numeric functions help you get accurate and meaningful results from your queries.

1234567891011
-- Use ROUND to round prices to the nearest whole number SELECT name, price, ROUND(price) AS rounded_price FROM products; -- Use CEILING to always round prices up SELECT name, price, CEILING(price) AS ceiling_price FROM products; -- Use FLOOR to always round prices down SELECT name, price, FLOOR(price) AS floor_price FROM products;
copy

You can also use numeric functions like ABS and POWER for more advanced calculations. The ABS function returns the absolute value of a number, which is useful when you need to remove any negative sign from a result. The POWER function raises a number to a specified power, allowing you to calculate exponents or squares of values as needed for your analysis.

1234567
-- Use MOD to find the remainder of stock divided by 10 SELECT name, stock, MOD(stock, 10) AS stock_remainder FROM products; -- Use SQRT to calculate the square root of the price SELECT name, price, SQRT(price) AS price_sqrt FROM products;
copy

1. Which function rounds a number up to the nearest integer?

2. What does the MOD function return?

3. Fill in the blanks to calculate the square root of the price for each product.

question mark

Which function rounds a number up to the nearest integer?

Select the correct answer

question mark

What does the MOD function return?

Select the correct answer

question-icon

Fill in the blanks to calculate the square root of the price for each product.

SELECT name, price, (price) AS price_sqrt FROM products;
Wireless Mouse|25.99|5.098039
Mechanical Keyboard|79.99|8.944272
USB-C Charger|19.50|4.415880
27-inch Monitor|229.99|15.165750
Bluetooth Headphones|59.99|7.745967
Webcam HD|39.99|6.324555
External Hard Drive 1TB|69.99|8.366600
Gaming Chair|149.99|12.247449
Laptop Stand|34.99|5.915475
Smartphone Holder|12.99|3.603883

Clique ou arraste solte itens e preencha os espaços

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 1
some-alt