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?
✗ Incorrect
The * operator multiplies values in SQL expressions.
What will this query return? <br>
SELECT 10 + 5 AS sum_result;✗ Incorrect
You can select expressions without a table; it returns the calculated value as a column.
How do you rename a calculated column in the result set?
✗ Incorrect
The AS keyword assigns an alias (name) to the calculated column.
Which function rounds a number to a specific decimal place in SQL?
✗ Incorrect
ROUND rounds numbers to the specified decimal places.
What is the result of dividing by zero in a SQL SELECT expression?
✗ Incorrect
Dividing by zero causes an error; it must be handled to avoid query failure.
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.