MySQL Database Quiz Questions

Course Name:MySQL
Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:CASE statement
Current Quiz Count:30
Progress
0%
Q1
True / False

The CASE statement in MySQL can only be used in SELECT queries.

Q2
True / False

In MySQL, the CASE statement must always have an ELSE clause.

Q3
True / False

In MySQL, the CASE statement can be used to compare different columns in a table.

Q4
True / False

In MySQL, the CASE statement can be used to replace IF statements.

Q5
True / False

MySQL supports a CASE statement inside another CASE statement.

Q6
True / False

MySQL's CASE statement can evaluate multiple conditions simultaneously.

Q7
True / False

MySQL's CASE statement can be used to execute multiple SQL statements.

Q8
True / False

In MySQL, you can use aggregate functions within a CASE statement.

Q9
True / False

MySQL allows the use of subqueries inside the CASE statement.

Q10
True / False

MySQL's CASE statement allows the use of data types that differ from those in the conditions being evaluated.

Q11
Single Choice

Which MySQL keyword is used to define alternative conditions in a CASE statement?

Q12
Single Choice

What will be the output of the following SQL code?

SQL Code
SELECT CASE
 WHEN 1 = 1 THEN 'True'
 ELSE 'False'
END AS result;
Q13
Single Choice

: In a MySQL CASE statement, what happens if none of the WHEN conditions are met and there is no ELSE clause?

Q14
Single Choice

What will be the result of this MySQL query?

SQL Code
SELECT CASE
 WHEN salary > 50000 THEN 'High'
 WHEN salary > 30000 THEN 'Medium'
 ELSE 'Low'
END AS salary_level
FROM employees WHERE employee_id = 101;
Q15
Single Choice

Consider the following SQL code. What will be the output for an employee with a salary of 45000?

SQL Code
SELECT CASE
 WHEN salary >= 50000 THEN 'A'
 WHEN salary >= 40000 THEN 'B'
 WHEN salary >= 30000 THEN 'C'
 ELSE 'D'
END AS grade
FROM employees WHERE employee_id = 202;
Q16
Single Choice

Which of the following MySQL CASE statement syntax is correct to check multiple columns?

Q17
Single Choice

What is the output of the following MySQL query?

SQL Code
SELECT CASE
 WHEN salary BETWEEN 60000 AND 80000 THEN 'Manager'
 WHEN salary BETWEEN 40000 AND 59999 THEN 'Senior Staff'
 WHEN salary BETWEEN 20000 AND 39999 THEN 'Junior Staff'
 ELSE 'Intern'
END AS position
FROM employees WHERE employee_id = 303;
Q18
Single Choice

Which of the following MySQL CASE statements will correctly return the string 'Yes' if the value of status is either 'active' or 'pending'?

SQL Code
SELECT CASE
 WHEN status IN ('active', 'pending') THEN 'Yes'
 ELSE 'No'
END AS status_check
FROM orders WHERE order_id = 101;
Q19
Single Choice

Given the following MySQL query, which value of score will output 'Pass with Distinction'?

SQL Code
SELECT CASE
 WHEN score >= 85 THEN 'Pass with Distinction'
 WHEN score >= 70 THEN 'Pass'
 ELSE 'Fail'
END AS result
FROM students WHERE student_id = 404;
Q20
Single Choice

Consider a scenario where you need to calculate a dynamic discount based on the total purchase amount. Which of the following MySQL queries correctly implements the logic using a CASE statement?

SQL Code
SELECT total_amount,
CASE
 WHEN total_amount >= 1000 THEN total_amount * 0.10
 WHEN total_amount >= 500 THEN total_amount * 0.05
 ELSE 0
END AS discount
FROM purchases;
Q21
Multiple Choice

Which 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;
Q22
Multiple Choice

Identify the correct SQL query that uses the CASE statement to display 'Yes' if the order amount is greater than 1000 and 'No' otherwise.

SQL Code
SELECT order_id, order_amount,
CASE
 WHEN order_amount > 1000 THEN 'Yes'
 ELSE 'No'
END AS high_value_order
FROM orders;
Q23
Multiple Choice

Which query uses the CASE statement to assign a discount percentage based on the 'customer_type' in the 'customers' table?

SQL Code
SELECT customer_id, customer_type,
CASE customer_type
 WHEN 'Regular' THEN 10
 WHEN 'Premium' THEN 20
 ELSE 5
END AS discount_percentage
FROM customers;
Q24
Multiple Choice

Determine 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;
Q25
Multiple Choice

Which 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;
Q26
Multiple Choice

Which SQL query uses the CASE statement to classify orders as 'High Priority' if the order amount is greater than 5000 and 'Normal Priority' otherwise?

SQL Code
SELECT order_id, order_amount,
CASE
 WHEN order_amount > 5000 THEN 'High Priority'
 ELSE 'Normal Priority'
END AS priority
FROM orders;
Q27
Multiple Choice

Determine the correct SQL query that uses the CASE statement to apply a 10% discount if the customer is 'Premium' and 5% if 'Regular'.

SQL Code
SELECT customer_id, customer_type,
CASE
 WHEN customer_type = 'Premium' THEN '10%'
 WHEN customer_type = 'Regular' THEN '5%'
 ELSE 'No Discount'
END AS discount
FROM customers;
Q28
Multiple Choice

Which 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;
Q29
Multiple Choice

Identify 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;
Q30
Multiple Choice

Which 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;