计算sql中的总时间

时间:2016-11-30 16:49:50

标签: oracle-sqldeveloper

无论如何,我可以将这两个查询一起添加吗?实际上我想要运动员表名属性的整体时间。

我已经尝试过Nested Select语句,但是它不能正常工作

这些是我的表格:

运动

Name          Null     Type         
------------- -------- ------------ 
ATHLETE_NO    NOT NULL NUMBER(38)   
FIRST_NAME    NOT NULL VARCHAR2(20) 
LAST_NAME     NOT NULL VARCHAR2(20) 
DOB           NOT NULL DATE         
ADDRESS_LINE1          CHAR(25)     
POSTCODE               CHAR(25)     
COUNTRY                CHAR(25)     
EMAIL                  VARCHAR2(20) 
GENDER                 VARCHAR2(10) 

TRIATHLETE_TP

Name             Null     Type         
---------------- -------- ------------ 
TRANSITION_TIME1          VARCHAR2(8)  
TRANSITION_TIME2          VARCHAR2(8)  
CYCLE_TIME                VARCHAR2(8)  
RUN_TIME                  VARCHAR2(8)  
SWIM_TIME                 VARCHAR2(8)  
RANKING                   NUMBER(38)   
ATHLETE_NO       NOT NULL NUMBER(38)   
RACE_NAME        NOT NULL VARCHAR2(20) 
RACE_DATE        NOT NULL DATE  

查询:

with x AS (
  select Transition_Time1,
         Transition_Time2,
         Cycle_Time,
         Swim_Time,
         Run_Time,

         substr(Transition_Time1,1,2) * 3600 +
         substr(Transition_Time1,4,2) * 60   +
         substr(Transition_Time1,7,2)            as t1_secs,
         substr(Transition_Time2,1,2) * 3600 +
         substr(Transition_Time2,4,2) * 60   +
         substr(Transition_Time2,7,2)            as t2_secs,
         substr(Cycle_Time,1,2) * 3600 +
         substr(Cycle_Time,4,2) * 60   +
         substr(Cycle_Time,7,2)            as C_secs,
         substr(Swim_Time,1,2) * 3600 +
         substr(Swim_Time,4,2) * 60   +
         substr(Swim_Time,7,2)            as S_secs,
         substr(Run_Time,1,2) * 3600 +
         substr(Run_Time,4,2) * 60   +
         substr(Run_Time,7,2)            as R_secs

  from TRIATHLETE_TP
  ),
y as (
  select Transition_Time1,Transition_Time2,Cycle_Time,Swim_Time,Run_Time,
         numtodsinterval(t1_secs + t2_secs + C_secs + S_secs + R_secs,'second') time_intvl
from x
  )
select Transition_Time1 , Transition_Time2 ,Cycle_Time,Swim_Time,Run_Time,
       extract(day from time_intvl) * 24 +
       extract(hour from time_intvl) ||':' ||
       extract(minute from time_intvl) ||':' ||
       extract(second from time_intvl) Overall_Time
from y

OR

select m.FIRST_NAME,m.LAST_NAME,t.Transition_Time1 , t.Transition_Time2 ,t.Cycle_Time,t.Swim_Time,t.Run_Time
from ATHLETE m JOIN TRIATHLETE_TP t
ON (m.ATHLETE_NO = t.ATHLETE_NO)

0 个答案:

没有答案