Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL query : employee relationships

I have a table called "employment" which looks like

enter image description here

if the boss column is empty it means he/she is the "CEO"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

and if he/she manages one another under boss column it means "Manager"

else it’s "Worker"

Finally it should look like

enter image description here

Can you help build some query to make the following result?

Thank you

>Solution :

SELECT name,
       CASE WHEN boss = ''   -- or maybe WHEN boss IS NULL 
            THEN 'CEO'
            WHEN EXISTS (SELECT NULL FROM employment t2 WHERE t1.name = t2.boss)
            THEN 'MANAGER'
            ELSE 'WORKER'
            END posession
FROM employment t1
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading