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:

  1. Compute the current age of each employee from their date_of_birth based on the current date.
  2. 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).
  3. 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.
  4. The query should output a table with two columns: age_interval and percent (of numeric datatype). The age_interval should be a string representation of the age range ('18-20', '26-40', '>40'), and percent should be the corresponding percentage of total employees, rounded to two decimal places.

GLHF!

SQL
Databases

Stats:

CreatedNov 7, 2023
PublishedNov 10, 2023
Warriors Trained343
Total Skips25
Total Code Submissions1143
Total Times Completed92
SQL Completions92
Total Stars10
% of votes with a positive feedback rating92% of 26
Total "Very Satisfied" Votes22
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes0
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • bornForThis Avatar
  • dfhwze Avatar
Ad