Q1
True / FalseThe CASE statement in MySQL can only be used in SELECT queries.
The CASE statement can be used in various SQL statements such as SELECT, UPDATE, DELETE, and SET.
Q2
True / FalseIn MySQL, the CASE statement must always have an ELSE clause.
The ELSE clause in a CASE statement is optional. If it is omitted and no condition is true, NULL is returned.
Q3
True / FalseIn MySQL, the CASE statement can be used to compare different columns in a table.
The CASE statement can compare different columns within the same table to make decisions based on their values.
Q4
True / FalseIn MySQL, the CASE statement can be used to replace IF statements.
The CASE statement can often be used in place of IF statements to perform conditional logic in queries.
Q5
True / FalseMySQL supports a CASE statement inside another CASE statement.
MySQL allows nested CASE statements, meaning you can place one CASE statement inside another.
Q6
True / FalseMySQL's CASE statement can evaluate multiple conditions simultaneously.
The CASE statement evaluates conditions sequentially and stops evaluating once a true condition is found.
Q7
True / FalseMySQL's CASE statement can be used to execute multiple SQL statements.
The CASE statement is used to return a single value based on conditional logic, not to execute multiple SQL statements.
Q8
True / FalseIn MySQL, you can use aggregate functions within a CASE statement.
Aggregate functions like SUM, COUNT, MAX, etc., can be used within CASE statements to perform conditional aggregation.
Q9
True / FalseMySQL allows the use of subqueries inside the CASE statement.
Subqueries can be used within a CASE statement to perform complex conditional logic.
Q10
True / FalseMySQL's CASE statement allows the use of data types that differ from those in the conditions being evaluated.
The CASE statement in MySQL can handle expressions and conditions involving different data types, but all return expressions must be of a compatible type.
Q21
Multiple ChoiceWhich SQL query uses the CASE statement to categorize employees based on their salary into 'High', 'Medium', and 'Low' categories?
SQL Code
SELECT employee_id, salary,
CASE
WHEN salary > 80000 THEN 'High'
WHEN salary BETWEEN 50000 AND 80000 THEN 'Medium'
ELSE 'Low'
END AS salary_category
FROM employees;
The CASE statement is used to evaluate the salary and assign a category based on the defined conditions.
Q24
Multiple ChoiceDetermine the correct SQL query that uses the CASE statement to show 'Pass' if a student's grade is 60 or above, and 'Fail' otherwise.
SQL Code
SELECT student_id, grade,
CASE
WHEN grade >= 60 THEN 'Pass'
ELSE 'Fail'
END AS result
FROM students;
The CASE statement evaluates the 'grade' and assigns 'Pass' or 'Fail' based on whether the grade meets the threshold.
Q25
Multiple ChoiceWhich SQL query uses the CASE statement to categorize transactions into 'Large', 'Medium', and 'Small' based on the transaction amount?
SQL Code
SELECT transaction_id, transaction_amount,
CASE
WHEN transaction_amount > 10000 THEN 'Large'
WHEN transaction_amount BETWEEN 5000 AND 10000 THEN 'Medium'
ELSE 'Small'
END AS transaction_size
FROM transactions;
The CASE statement categorizes the transaction amount into 'Large', 'Medium', and 'Small' based on the specified conditions.
Q28
Multiple ChoiceWhich query uses the CASE statement to determine the grade of a student as 'A', 'B', 'C', or 'F' based on the score in the 'students' table?
SQL Code
SELECT student_id, score,
CASE
WHEN score >= 90 THEN 'A'
WHEN score >= 80 THEN 'B'
WHEN score >= 70 THEN 'C'
ELSE 'F'
END AS grade
FROM students;
The CASE statement categorizes the score into different grades based on the defined thresholds.
Q29
Multiple ChoiceIdentify the correct SQL query that uses the CASE statement to label an employee's experience level as 'Senior', 'Mid', or 'Junior' based on years of experience.
SQL Code
SELECT employee_id, years_of_experience,
CASE
WHEN years_of_experience > 10 THEN 'Senior'
WHEN years_of_experience BETWEEN 5 AND 10 THEN 'Mid'
ELSE 'Junior'
END AS experience_level
FROM employees;
The CASE statement categorizes the experience level based on the number of years of experience.
Q30
Multiple ChoiceWhich SQL query correctly uses the CASE statement to display 'Above Average' if a product's price is higher than the average price, and 'Below Average' otherwise?
SQL Code
SELECT product_id, price,
CASE
WHEN price > (SELECT AVG(price) FROM products) THEN 'Above Average'
ELSE 'Below Average'
END AS price_category
FROM products;
This query uses a subquery within the CASE statement to compare each product's price to the average price of all products.