SQL | oracle DB |给定开始和结束日期的每个位置的时间差

时间:2017-11-15 10:48:49

标签: java sql

我没有得到正确的结果,我尝试了下面的查询,并得到了一些奇怪的小数

  CREATE TABLE "EXAMPLE" 
   ("LOCATION_I" NUMBER NOT NULL ENABLE, 
    "START_TS" DATE, 
    "END_TS" DATE, 
     CONSTRAINT "TABLE1_PK" PRIMARY KEY ("LOCATION_I")
    )  ;

Insert into EXAMPLE (LOCATION_I,START_TS,END_TS) values (1,to_date('14-11-17','DD-MM-RR'),to_date('15-11-17','DD-MM-RR'));
Insert into EXAMPLE (LOCATION_I,START_TS,END_TS) values (2,to_date('13-11-17','DD-MM-RR'),to_date('14-11-17','DD-MM-RR'));
Insert into EXAMPLE (LOCATION_I,START_TS,END_TS) values (3,to_date('12-11-17','DD-MM-RR'),to_date('13-11-17','DD-MM-RR'));

select LOCATION_I, avg(END_TS - START_TS) from EXAMPLE  where END_TS is not null  GROUP BY LOCATION_I;

请建议解决方案..

这是更大的sql的一部分。 .................................................. .................................................. .................................................. .................................................. .................................................. ...........

0 个答案:

没有答案