oracle语句两张表相减,看最后是否有误差

有三张表,一张是系统表dual,一张是自己的表A,一张是自己的表B 

其中A和B查看最后得出的时间,然后和系统表相比,最后相减,看是否有相差,误差多少秒

select total_seconds1,total_seconds2,total_seconds1-total_seconds2 AS gap from 
(select (hours+minutes+seconds) AS total_seconds1 from (
  select
  to_char(sysdate,('HH24'))*60*60 AS hours,
  to_char(sysdate,('mi'))*60 AS minutes,
  to_char(sysdate,'ss') AS seconds
  from dual
  )),
(
select (hours+minutes+seconds) AS total_seconds2 from (   select   to_char(sysdate,('HH24'))*60*60 AS hours,   to_char(sysdate,('mi'))*60 AS minutes,   to_char(sysdate,'ss') AS seconds   from(     select     to_char(f_quotation_time,'HH24:mi:ss')     from A tq,B tc where     tq.f_contract_id = (select f_id from B where f_symbol = 'AG') and tc.f_symbol = 'AG' )   ));

 

 

解读:

解读:

AS:是给前面的结果指定一个新的列

HH21:时

mi:分

ss:秒

 

1,首先找出A和B的时间最后算出秒数,然后在找出两表相减,得出结果,结果gap列是新增的结果列是误差值
2,下面B和C的查询中是先找的时分秒,之后算出总秒
3,这个看着比较多,简单的方法还未找到,还有一种是直接时分秒相减但是提示ORA-01722:无效数字,然后没有找到处理方式就放弃这种了,最后用秒数相减

 

 最后得出零误差

posted @ 2020-05-19 13:55  小渣渣呦!!!  阅读(1104)  评论(0编辑  收藏  举报