SQL Database Conditional Flow Quiz

SQL Database
0 Passed
0% acceptance

A 35-question quiz exploring conditional logic, CASE expressions, value mapping, multi-branch logic, derived classifications, and conditional aggregation.

35 Questions
~70 minutes
1

Question 1

An analyst wants to convert numeric ratings into labels such as 'Low', 'Medium', and 'High' when producing a report. Which structure enables grouping values into categories?

A
A CASE expression with multiple WHEN branches
B
A UNIQUE constraint
C
A composite primary key
D
A CHECK constraint only
2

Question 2

A team wants to show 'Active' for customers with recent purchases and 'Dormant' otherwise. What feature allows returning different labels depending on conditions?

A
Conditional CASE logic
B
Indexing strategy
C
A reference table only
D
A UNIQUE index
3

Question 3

A reviewer wants to label orders as 'Large' when quantity is above 50 and 'Standard' otherwise. Which CASE pattern fits this?

A
A searched CASE with WHEN quantity > 50
B
A GROUP BY clause
C
A CROSS JOIN
D
A DISTINCT selection
4

Question 4

A finance report displays 'Premium Tier' for balances above a threshold and 'Standard Tier' otherwise. Which CASE structure supports fallback logic?

A
CASE ... WHEN ... ELSE ... END
B
CROSS APPLY
C
A UNIQUE key
D
Hash partitioning
5

Question 5

A table stores status codes like 1, 2, and 3. A designer wants readable labels such as 'Pending', 'Approved', and 'Rejected'. What technique allows mapping discrete numeric values?

A
Simple CASE comparing exact values
B
Aggregate functions
C
Self-join logic
D
Window frames
6

Question 6

A merch team wants to show 'Sale Item' if discount is non-zero, else show 'Regular'. Which logic allows evaluation based on a boolean-like condition?

A
CASE with WHEN discount > 0
B
GROUP BY discount
C
A foreign key reference
D
A UNIQUE filter
7

Question 7

A designer wants to show different greetings based on user language preference. What structure handles multiple mutually exclusive options?

A
Multiple WHEN clauses with CASE
B
HAVING clause only
C
JOIN with no condition
D
UNION ALL without filters
8

Question 8

A system displays different shipping messages depending on region. Why might CASE be preferred over storing region names directly in the message column?

A
CASE keeps logic centralized rather than duplicating messages
B
CASE increases write speed
C
CASE enforces constraints
D
CASE removes join needs permanently
9

Question 9

A company wants to classify products as 'Overstocked', 'Balanced', or 'Low Stock'. What does CASE help them achieve?

A
Transform raw numeric stock into descriptive categories
B
Replace data types
C
Create physical indexes
D
Remove constraints
10

Question 10

A designer needs to generate custom sort order, placing VIP customers at the top and others afterwards. What advantage does CASE provide inside ORDER BY?

A
CASE lets you compute custom ordering ranks
B
CASE prevents sorting entirely
C
CASE replaces the ORDER BY
D
CASE forces alphabetical order
11

Question 11

A restaurant app displays 'Lunch Menu' or 'Dinner Menu' based on time of day. Why is CASE appropriate?

A
It returns different computed expressions based on conditions
B
It changes the table structure
C
It enforces primary keys
D
It performs encryption
12

Question 12

In reporting, an analyst wants NULL scores to be displayed as 'No Score'. Which CASE feature supports this?

A
ELSE to provide a fallback label
B
A GROUP BY replacement
C
HAVING filter only
D
TRIM functions
13

Question 13

A product page displays 'Out of Stock' when quantity is zero. Why is CASE preferable to storing this text permanently?

A
It avoids storing repetitive, derived text
B
It changes normalization forms
C
It enforces check constraints
D
It generates new keys
14

Question 14

A team wants to categorize transactions over $1000 as 'High Value'. What CASE form supports conditions that involve comparison operators?

A
Searched CASE
B
Simple CASE
C
JOIN CASE
D
Constraint CASE
15

Question 15

A user wants to display different category labels depending on product type, using direct equality checks. Which CASE variation is suitable?

A
Simple CASE
B
Searched CASE
C
CASE ALL
D
MERGE CASE
16

Question 16

Analysts reviewing survey scores want to map groups such as 1–3 as 'Low', 4–7 as 'Medium', and 8–10 as 'High'. What characteristic of CASE makes this possible?

A
CASE supports multiple non-overlapping branches
B
CASE applies default indexes
C
CASE modifies schema
D
CASE suppresses rows
17

Question 17

A report wants to switch between two values depending on a single condition—if overdue, show 'Late'; otherwise show 'On Time'. Which simplified CASE structure fits?

A
Two-branch CASE with ELSE fallback
B
UNION of labels
C
CROSS JOIN filter
D
MIN/MAX logic
18

Question 18

A dashboard displays accounts as 'Inactive' if last login is more than one year ago. Which CASE feature helps evaluate date-based conditions?

A
Searched CASE using date comparisons
B
JOINs only
C
PRIMARY KEY selection
D
DISTINCT operator
19

Question 19

A data analyst wants a label for every region except one, which should display a special message. Why does CASE help maintain this exception?

A
CASE allows explicit branch ordering, placing special conditions first
B
CASE auto-corrects regions
C
CASE removes unwanted rows
D
CASE bypasses filters
20

Question 20

A system assigns risk levels to transactions based on multiple attributes like amount, location, and time. Which CASE feature makes this easier?

A
Multiple WHEN conditions evaluating various expressions
B
Indexes only
C
Strictly equality-only checks
D
SET operations
21

Question 21

A category label depends on whether a numeric field falls within certain ranges. Why must CASE branches be ordered carefully?

A
CASE returns the first matching branch only
B
CASE randomly picks branches
C
CASE requires alphabetical order
D
CASE requires equality first
22

Question 22

This logic labels orders depending on quantity. What output appears when quantity is 80?

sql
SELECT CASE
  WHEN quantity > 50 THEN 'Large'
  ELSE 'Standard'
END AS size_label;
A
Large
B
Standard
C
NULL
D
Unknown
23

Question 23

This expression maps role codes to readable labels. What label is returned for code = 2?

sql
SELECT CASE role
  WHEN 1 THEN 'Admin'
  WHEN 2 THEN 'Staff'
  ELSE 'Guest'
END;
A
Staff
B
Admin
C
Guest
D
NULL
24

Question 24

What does this CASE produce if stock is NULL?

sql
SELECT CASE
  WHEN stock = 0 THEN 'Empty'
  ELSE 'Available'
END;
A
Available
B
Empty
C
NULL
D
Error
25

Question 25

What category does this CASE assign when score = 5?

sql
SELECT CASE
  WHEN score >= 8 THEN 'High'
  WHEN score >= 4 THEN 'Medium'
  ELSE 'Low'
END;
A
Medium
B
High
C
Low
D
NULL
26

Question 26

This CASE uses direct equality. What is returned when type = 'B'?

sql
SELECT CASE item_type
  WHEN 'A' THEN 'Priority'
  WHEN 'B' THEN 'Regular'
  ELSE 'Other'
END;
A
Regular
B
Priority
C
Other
D
NULL
27

Question 27

For price = 0, what does this CASE produce?

sql
SELECT CASE
  WHEN price > 0 THEN 'Paid'
  ELSE 'Free'
END;
A
Free
B
Paid
C
NULL
D
Unknown
28

Question 28

This CASE handles text states. What is returned for state = 'C'?

sql
SELECT CASE state
  WHEN 'A' THEN 'Open'
  WHEN 'B' THEN 'Pending'
  ELSE 'Closed'
END;
A
Closed
B
Open
C
Pending
D
NULL
29

Question 29

What label appears when units = 12?

sql
SELECT CASE
  WHEN units >= 20 THEN 'Bulk'
  WHEN units >= 10 THEN 'Standard'
  ELSE 'Small'
END;
A
Standard
B
Bulk
C
Small
D
NULL
30

Question 30

For rating = 9, which label appears?

sql
SELECT CASE
  WHEN rating < 3 THEN 'Poor'
  WHEN rating < 7 THEN 'Average'
  ELSE 'Excellent'
END;
A
Excellent
B
Average
C
Poor
D
NULL
31

Question 31

When views = NULL, what is produced?

sql
SELECT CASE
  WHEN views > 1000 THEN 'Popular'
  ELSE 'Normal'
END;
A
Normal
B
Popular
C
NULL
D
Error
32

Question 32

What value is returned here for dept = 'HR'?

sql
SELECT CASE dept
  WHEN 'HR' THEN 'Admin'
  WHEN 'IT' THEN 'Tech'
  ELSE 'Other'
END;
A
Admin
B
Tech
C
Other
D
NULL
33

Question 33

What happens when salary = 3000?

sql
SELECT CASE
  WHEN salary > 5000 THEN 'High'
  WHEN salary > 2000 THEN 'Medium'
  ELSE 'Low'
END;
A
Medium
B
High
C
Low
D
NULL
34

Question 34

For level = 0, what does this return?

sql
SELECT CASE
  WHEN level >= 5 THEN 'Expert'
  WHEN level >= 1 THEN 'Intermediate'
  ELSE 'New'
END;
A
New
B
Intermediate
C
Expert
D
NULL
35

Question 35

For points = 15, what label is assigned?

sql
SELECT CASE
  WHEN points >= 20 THEN 'Gold'
  WHEN points >= 10 THEN 'Silver'
  ELSE 'Bronze'
END;
A
Silver
B
Gold
C
Bronze
D
NULL

QUIZZES IN SQL Database