PostgreSQL Database Quiz Questions

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

In PostgreSQL, the CASE statement can be used within a SELECT statement to perform conditional logic.

Q2
True / False

In PostgreSQL, the CASE statement must always include an ELSE clause.

Q3
True / False

In PostgreSQL, the CASE statement can be used to update rows in an UPDATE statement.

Q4
True / False

In PostgreSQL, the CASE statement can be used in combination with aggregate functions like SUM and COUNT.

Q5
True / False

In PostgreSQL, nested CASE statements are not allowed.

Q6
True / False

In PostgreSQL, the CASE statement can only be used in the SELECT clause.

Q7
True / False

In PostgreSQL, the CASE statement can be used within a WHERE clause to filter rows based on conditional logic.

Q8
True / False

In PostgreSQL, using a CASE statement within a JOIN condition can significantly improve query performance.

Q9
True / False

In PostgreSQL, the CASE statement can evaluate complex expressions, including subqueries, within each WHEN clause.

Q10
True / False

In PostgreSQL, a CASE statement without an ELSE clause will return a default value specified by the database configuration.

Q11
Single Choice

What does the CASE statement in PostgreSQL allow you to do?

Q12
Single Choice

Which of the following is a valid CASE statement in PostgreSQL?

Q13
Single Choice

How do you ensure that a CASE statement in PostgreSQL handles all possible cases?

Q14
Single Choice

Given the following PostgreSQL query, what will the output be for age = 25?

SQL Code
SELECT
 name,
 CASE
 WHEN age < 18 THEN 'Minor'
 WHEN age >= 18 AND age < 65 THEN 'Adult'
 ELSE 'Senior'
 END AS age_group
FROM users;
Q15
Single Choice

How can you combine a CASE statement with aggregate functions in PostgreSQL?

Q16
Single Choice

What will be the result of the following PostgreSQL CASE statement?

SQL Code
SELECT
 CASE
 WHEN salary > 50000 THEN 'High'
 WHEN salary < 30000 THEN 'Low'
 ELSE 'Medium'
 END AS salary_range
FROM employees
WHERE salary IS NULL;
Q17
Single Choice

What will be the output of the following query if status is NULL in PostgreSQL?

SQL Code
SELECT
 CASE
 WHEN status = 'active' THEN 'Active User'
 WHEN status = 'inactive' THEN 'Inactive User'
 ELSE 'Unknown'
 END AS user_status
FROM users;
Q18
Single Choice

How can you optimize the following PostgreSQL query using CASE?

SQL Code
SELECT
 CASE
 WHEN age BETWEEN 13 AND 19 THEN 'Teenager'
 WHEN age < 13 THEN 'Child'
 ELSE 'Adult'
 END AS age_group,
 COUNT(*)
FROM users
GROUP BY age_group;
Q19
Single Choice

Consider the following PostgreSQL query. What will be the result if employee_id does not exist in the employees table?

SQL Code
SELECT
 employee_id,
 CASE
 WHEN employee_id IS NOT NULL THEN 'Exists'
 ELSE 'Does Not Exist'
 END AS employee_status
FROM employees;
Q20
Single Choice

How can you use a CASE statement to handle NULL values explicitly in PostgreSQL?

SQL Code
SELECT
 product_id,
 CASE
 WHEN price IS NULL THEN 'Price Missing'
 ELSE 'Price Available'
 END AS price_status
FROM products;
Q21
Multiple Choice

Which SQL scripts correctly use the CASE statement to categorize employees based on their salary in PostgreSQL?

Q22
Multiple Choice

Identify the SQL scripts that correctly use the CASE statement to assign bonus percentages in PostgreSQL.

Q23
Multiple Choice

Which SQL scripts correctly use the CASE statement to generate a custom label for departments based on the number of employees in PostgreSQL?

Q24
Multiple Choice

Determine the SQL scripts that correctly use the CASE statement to apply discounts based on order quantity in PostgreSQL.

Q25
Multiple Choice

Which SQL scripts correctly use the CASE statement to handle NULL values in PostgreSQL?

Q26
Multiple Choice

Identify the SQL scripts that correctly use the CASE statement within an ORDER BY clause in PostgreSQL.

Q27
Multiple Choice

Which SQL scripts correctly use the CASE statement to modify column values during data retrieval in PostgreSQL?

Q28
Multiple Choice

Determine the SQL scripts that correctly use the CASE statement to handle multiple conditions in PostgreSQL.

Q29
Multiple Choice

Identify the SQL scripts that correctly use nested CASE statements in PostgreSQL.

Q30
Multiple Choice

Which SQL scripts correctly use the CASE statement to create calculated fields in PostgreSQL?