6 kyu
Current Age Distribution of Employees
Description:
The HR department requests a report on the percentage of employees within specific age intervals to aid in understanding the company's generational workforce distribution.
You have been provided with a database containing an employees
table with the following schema:
employee_id
(integer): A unique identifier for each employee.date_of_birth
(date): The birth date of the employee
Your task is to write an SQL query that calculates the current age of each employee, categorizes these ages into intervals (18-20, 26-40, and above 40 years), and returns the percentage of employees within each interval. Round all percentages to two decimal places.
Requirements:
- Compute the current age of each employee from their
date_of_birth
based on the current date. - Use the calculated ages to categorize employees into the following age brackets: 18-20 (inclusive), 26-40, and above 40. Ensure the age ranges include the entire span (e.g., up to but not including 21 years for the 18-20 bracket).
- Calculate the percentage of the total workforce that falls within each age bracket, rounding the result to two decimal places. For age brackets with no employees, the query should display 0.0.
- The query should output a table with two columns:
age_interval
andpercent
(ofnumeric
datatype). Theage_interval
should be a string representation of the age range ('18-20', '26-40', '>40'), andpercent
should be the corresponding percentage of total employees, rounded to two decimal places.
GLHF!
SQL
Databases
Similar Kata:
Stats:
Created | Nov 7, 2023 |
Published | Nov 10, 2023 |
Warriors Trained | 343 |
Total Skips | 25 |
Total Code Submissions | 1143 |
Total Times Completed | 92 |
SQL Completions | 92 |
Total Stars | 10 |
% of votes with a positive feedback rating | 92% of 26 |
Total "Very Satisfied" Votes | 22 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |