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:无效数字,然后没有找到处理方式就放弃这种了,最后用秒数相减
最后得出零误差
相关推荐
lklong 2020-11-22
oraclemch 2020-11-06
shilukun 2020-10-10
周嘉笙 2020-11-09
iilegend 2020-10-19
EricRay 2020-10-16
zhuzhufxz 2020-09-16
dataminer 2020-08-17
bfcady 2020-08-16
Hody 2020-08-16
FightFourEggs 2020-08-16
数据库设计 2020-08-16
Seandba 2020-08-16
Omega 2020-08-16
zjyzz 2020-08-16
yanghuatong 2020-08-16
ktyl000 2020-08-16
dbasunny 2020-08-16