6 kyu

Generation Categorization

Description:

Assume you have a PostgreSQL database with a table named "users". The "users" table has the following columns:

  • id (integer): a unique identifier for each user.
  • name (text): the name of the user.
  • birthdate (date): the user's birth date.

The generational categories are generally defined as follows:

  • Generation Z: Born from 1997 to 2012 (inclusive)
  • Millennials: Born from 1981 to 1996
  • Generation X: Born from 1965 to 1980
  • Baby Boomers: Born from 1946 to 1964
  • Silent Generation: Born from 1928 to 1945
  • Greatest Generation: Born in 1927 or earlier

Your SQL query should return all users sorted by id in asc order from the users table with an additional generation field that indicates the generation to which each user belongs based on the above definitions.

Sounds simple? You are not allowed to use the CASE WHEN operator for this task :-)

GLHF!

Desired Output

The desired output should look like this:

idnamebirthdategeneration
1Mr. Nerissa Cremin1994-03-15Millennials
2Mattie Lind1961-04-05Baby Boomers
3Cody Murray1966-12-05Generation X
...
SQL
Databases
Restricted

Stats:

CreatedJul 8, 2023
PublishedJul 8, 2023
Warriors Trained308
Total Skips27
Total Code Submissions547
Total Times Completed161
SQL Completions161
Total Stars7
% of votes with a positive feedback rating92% of 31
Total "Very Satisfied" Votes27
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • bornForThis Avatar
  • dfhwze Avatar
Ad