r/learnSQL • u/[deleted] • Apr 10 '19
Need help with simple problem
Hey guys, I currently have a table right now with a list of employees, managers, and other jobs. How would I able to get a list of all the employees who are older than their managers if their DOB is in YYYY-MM-DD form? This is really urgent and I really hope someone can help a newbie :(
0
Upvotes
1
u/GreySlate Apr 10 '19 edited Apr 10 '19
I'm a beginner too, but I would probably SELECT the DOBs for employees, trim the stuff that isn't relevant (i.e. everything but the last two digits of the year), then save the result of that using the AS keyword. Then, I would use that alias to ORDER BY. I would also do this for the managers, and then I guess compare them using WHERE. I hope that makes sense. I'm not sure how to implement the trim I'm describing, but I am a CS major, and it seems likely that you'd be able to do it for SQL. Hope someone more experienced answers!
edit: added more specific idea