0
0
SQLquery~5 mins

SELECT with expressions and calculations in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the SELECT statement do in SQL?
The SELECT statement retrieves data from a database table and returns it as a result set.
Click to reveal answer
beginner
How can you perform calculations in a SELECT statement?
You can use arithmetic operators like +, -, *, / directly in the SELECT clause to calculate values from columns or constants.
Click to reveal answer
beginner
Example: What does this query do? <br>SELECT price, quantity, price * quantity AS total_cost FROM sales;
It selects the price and quantity columns from the sales table and calculates a new column total_cost by multiplying price and quantity for each row.
Click to reveal answer
intermediate
Can you use functions in SELECT expressions? Give an example.
Yes, you can use functions like ROUND, ABS, or CONCAT in SELECT expressions. For example: <br>SELECT ROUND(price * quantity, 2) AS total_rounded FROM sales; rounds the total cost to 2 decimal places.
Click to reveal answer
intermediate
What happens if you divide by zero in a SELECT calculation?
Dividing by zero causes an error in SQL. You should handle it using CASE or NULLIF to avoid errors, for example: <br>SELECT price / NULLIF(quantity, 0) AS safe_division FROM sales;
Click to reveal answer
Which operator is used to multiply two columns in a SELECT statement?
A/
B+
C-
D*
What will this query return? <br>SELECT 10 + 5 AS sum_result;
AA list of numbers from 10 to 5
BAn error because no table is specified
CA column named sum_result with value 15
DNULL
How do you rename a calculated column in the result set?
AUsing GROUP BY
BUsing AS keyword
CUsing WHERE clause
DUsing ORDER BY
Which function rounds a number to a specific decimal place in SQL?
AROUND
BABS
CCONCAT
DLENGTH
What is the result of dividing by zero in a SQL SELECT expression?
AAn error occurs
BReturns zero
CReturns NULL automatically
DReturns infinity
Explain how to use expressions and calculations in a SELECT statement with an example.
Think about multiplying two columns and giving the result a name.
You got /4 concepts.
    Describe how to safely handle division in SELECT expressions to avoid errors.
    Consider how to avoid dividing by zero in your calculation.
    You got /3 concepts.