Hello
I have to find two longest serving employees for each job in this table
employees(empname,job,hiredate). how can I do it? thanx.How do you know the termination date for each employee? Without that, I can't figure out how to compute their length of service.
Did the instructor give you a more detailed problem specification, or was this all that they gave you?
-PatP|||I don't need termination date. I need to find out which two current employees are working longer than the others.|||Assuming the employee table is only current employees, try:
SELECT EMPNAME, HIREDATE
FROM EMPLOYEES A
WHERE 2 > (SELECT COUNT(*) FROM EMPLOYEES B
WHERE A.HIREDATE > B.HIREDATE);|||urquel: for each job|||That's simple:
SELECT EMPNAME, JOB, HIREDATE
FROM EMPLOYEES A
WHERE 2 > (SELECT COUNT(*) FROM EMPLOYEES B
WHERE A.HIREDATE > B.HIREDATE AND A.JOB = B.JOB);|||That's simple:
SELECT EMPNAME, JOB, HIREDATE
FROM EMPLOYEES A
WHERE 2 > (SELECT COUNT(*) FROM EMPLOYEES B
WHERE A.HIREDATE > B.HIREDATE AND A.JOB = B.JOB);
Thanx a lot!!!
That's what I needed!sql
No comments:
Post a Comment