Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification #9

Open
silviudanielpopescu opened this issue Nov 20, 2020 · 3 comments
Open

Clarification #9

silviudanielpopescu opened this issue Nov 20, 2020 · 3 comments

Comments

@silviudanielpopescu
Copy link

Hi Mo,
Only a small clarification here - "Who is the oldest employee?" query is returning the age not the name of the oldest employee...
Your question is opening a challenge and accept it - I will come back with the solution.
Thanks.

@silviudanielpopescu
Copy link
Author

Found a way:

SELECT *, AGE(birth_date) AS "Age" FROM employees
ORDER BY "Age" DESC;
6 records matching...

@ai77ee
Copy link

ai77ee commented Jan 13, 2021

that's right!
I spent so much time thinking how to resolved it in order to get who is the oldest employee
and I came with this solution:

select *,  AGE(birth_date)
from employees
WHERE AGE(birth_date)=(
select  MAX(AGE(birth_date)) 
from employees
)

and yep! there's 6 records matching who is the oldest employee

@AAB007209
Copy link

AAB007209 commented Aug 3, 2021

@silviudanielpopescu @aimeehg
You can do a simple query as well instead of writing big queries. First find the minimum birth_date using
" SELECT min(employees.birth_date) FROM employees; "........ and then do this below query.
SELECT employees FROM public.employees WHERE employees.birth_date = '1952-02-01';

Why min birth_date is because they are the oldest employees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants