好吧,只有当所有事情都发生在同一天时才有意义。例如:
SQL> create table test
2 (received_time varchar2(20),
3 processes_date date);
Table created.
SQL> insert into test values
2 ('1430', to_date('23.05.2018 16:10:00', 'dd.mm.yyyy hh24:mi:ss'));
1 row created.
SQL> insert into test values
2 ('1430', to_date('23.05.2018 18:10:00', 'dd.mm.yyyy hh24:mi:ss'));
1 row created.
SQL> insert into test values
2 ('1430', to_date('23.05.2018 14:50:00', 'dd.mm.yyyy hh24:mi:ss'));
1 row created.
SQL>
如果我们将 RECEIVED_TIME 转换为 DATE 数据类型,我们会得到:
SQL> select to_date(received_time, 'hh24mi') rectim,
2 processes_date
3 from test;
RECTIM PROCESSES_DATE
---------------- ----------------
01.05.2018 14:30 23.05.2018 16:10
01.05.2018 14:30 23.05.2018 18:10
01.05.2018 14:30 23.05.2018 14:50
SQL>
啊哈; RECEIVED_TIME 被“转换”为当月的第一天。我们将对PROCESSES_DATE 执行相同的操作,将TO_DATE 和TO_CHAR 函数与适当的格式掩码结合使用:
SQL> select to_date(received_time, 'hh24mi') rectim,
2 to_date(to_char(processes_date, 'hh24mi'), 'hh24mi') proctim
3 from test;
RECTIM PROCTIM
---------------- ----------------
01.05.2018 14:30 01.05.2018 16:10
01.05.2018 14:30 01.05.2018 18:10
01.05.2018 14:30 01.05.2018 14:50
SQL>
不错;现在我们可以做一些计算,看看哪一行花了超过 30 分钟才完成;我将值四舍五入到小数点后 5 位以节省空间。另外,请注意,我正在逐步进行操作,以便您了解我们如何达到 分钟,因为两个 DATE 数据类型值的差异是 天数 em> 他们之间:
SQL> with inter as
2 (select to_date(received_time, 'hh24mi') rectim,
3 to_date(to_char(processes_date, 'hh24mi'), 'hh24mi') proctim
4 from test
5 )
6 select
7 proctim,
8 rectim,
9 round(proctim - rectim, 5) days,
10 round((proctim - rectim) * 24, 5) hours,
11 round((proctim - rectim) * 26 * 60, 5) minutes
12 from inter;
PROCTIM RECTIM DAYS HOURS MINUTES
---------------- ---------------- ---------- ---------- ----------
01.05.2018 16:10 01.05.2018 14:30 ,06944 1,66667 108,33333
01.05.2018 18:10 01.05.2018 14:30 ,15278 3,66667 238,33333
01.05.2018 14:50 01.05.2018 14:30 ,01389 ,33333 21,66667
SQL>
最后,你要找的结果:
SQL> with inter as
2 (select to_date(received_time, 'hh24mi') rectim,
3 to_date(to_char(processes_date, 'hh24mi'), 'hh24mi') proctim
4 from test
5 )
6 select
7 proctim,
8 rectim,
9 round((proctim - rectim) * 26 * 60, 5) minutes
10 from inter
11 where (proctim - rectim) * 26 * 60 > 30;
PROCTIM RECTIM MINUTES
---------------- ---------------- ----------
01.05.2018 16:10 01.05.2018 14:30 108,33333
01.05.2018 18:10 01.05.2018 14:30 238,33333
SQL>