關鍵點在於如何得到下一條日期。mysql
mysql 和 sql serversql
select x.*,DATEDIFF(day,x.HIREDATE,x.next_hd) diff from( select e.DEPTNO,e.ENAME,e.HIREDATE,(select MIN(HIREDATE) from emp d where d.HIREDATE>e.HIREDATE) next_hd from EMP e where e.DEPTNO=10 ) x