Topic: SQL CASE
Statement for Conditional Categorization
This lesson shows how to use the CASE
statement in SQL to classify employees based on their performance score.
Use Case:
In performance appraisal dashboards, categorizing employees into “Excellent,” “Good,” or “Needs Improvement” is a common business requirement.
SQL Query:
SELECT Name, CASE WHEN PerformanceScore >= 90 THEN 'Excellent' WHEN PerformanceScore >= 70 THEN 'Good' ELSE 'Needs Improvement' END AS Rating FROM hr_employees;
Output Example:
Name | Rating |
---|---|
Rajesh Kumar | Excellent |
Ananya Sharma | Good |
James Mathew | Needs Improvement |
Insight:
This query is useful for HR teams to group employees into performance bands for reviews, incentives, or training plans.