Sql确定两个日期之间的秒、分、小时数

DB2

1  select dy*24 hr, dy*24*60 min, dy*24*60*60 sec

2    from (

3  select ( days(max(case when ename = 'WARD'

4                    then hiredate

5               end)) -

6           days(max(case when ename = 'ALLEN'

7                    then hiredate

8               end))

9         ) as dy

10    from emp

11         ) x

MySQL和SQL Server

1  select datediff(day,allen_hd,ward_hd)*24 hr,

2         datediff(day,allen_hd,ward_hd)*24*60 min,

3         datediff(day,allen_hd,ward_hd)*24*60*60 sec

4    from (

5  select max(case when ename = 'WARD'

6                   then hiredate

7             end) as ward_hd,

8         max(case when ename = 'ALLEN'

9                  then hiredate

10             end) as allen_hd

11    from emp

12         ) x

Oracle和PostgreSQL

1  select dy*24 as hr, dy*24*60 as min, dy*24*60*60 as sec

2    from (

3  select (max(case when ename = 'WARD'

4                  then hiredate

5             end) -

6         max(case when ename = 'ALLEN'

7                  then hiredate

8             end)) as dy

9    from emp

10         ) x

select max(case when ename = 'WARD'

then hiredate

end) as ward_hd,

max(case when ename = 'ALLEN'

then hiredate

end) as allen_hd

from emp

WARD_HD     ALLEN_HD

----------- -----------

22-FEB-1981 20-FEB-1981

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120