w3resource

SQL Exercises: Display the result of an arithmetic expression

SQL Basic Select Statement: Exercise-5 with Solution.

Write an SQL query to display the result of an arithmetic expression.

Sample Solution:

-- This query performs a series of arithmetic operations: addition, subtraction, and multiplication.
SELECT 10 + 15 - 5 * 2;

Output of the Query:

?column?
15

Code Explanation:

The given SQL query that selects a column with a single row, which contains the result of the mathematical expression 10 + (15 - (5 * 2)) = 15.

Syntax of display the result of an arithmetic simplification

Visual presentation:

Result of an arithmetic simplification

Practice Online


Query Visualization:

Duration:

Query visualization of Display the result of an arithmetic simplification - Duration

Rows:

Query visualization of Display the result of an arithmetic simplification - Rows

Cost:

Query visualization of Display the result of an arithmetic simplification - Cost

 

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: Display the sum of two numbers.
Next SQL Exercise: Select specific columns from a table.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sql-exercises/sql-retrieve-exercise-5.php