Vertica在连接值上插值先前的值

时间:2018-08-20 16:40:08

标签: vertica

我有一个表A,它有两个时间戳记列A.time1和A.time2,另一个表B有一个时间戳记列B.time。 X如何在X值为A.time1的小时,分​​钟+ A.time2的秒内插值先前的值B.time?

类似

Option Explicit       

     Sub SendEmailXLS()
     Dim appExcel As Excel.Application
     Dim objActiveWkb As Object
     Dim ActiveWorkbook As Object
     Dim objActiveChrt As Object

    Set objActiveWkb = appExcel.Application.ActiveWorkbook
    Set objActiveChrt = appExcel.Application.ActiveChart
    With objActiveWkb


   appExcel.Selection.SpecialCells(xlCellTypeConstants, 23).Select
   appExcel.Sheets.Add
   objActiveWkb.PivotCaches.Create(SourceType:=1, SourceData:= _
    "xxx!R1C1:R10C34", Version:=1 _
    ).CreatePivotTable TableDestination:="Sheet1!R1C1", TableName:= _
    "BDA Pivot Chart", DefaultVersion:=xlPivotTableVersion10
.Worksheets(1).Select
.Worksheets(1).Range("A1").Select
.Worksheets(1).Shapes.AddChart2(201, 51).Select
objActiveChrt.PivotLayout.PivotTable.AddDataField
objActiveChrt.PivotLayout. _
    PivotTable.PivotFields("Traffic"), "Sum of Traffic", xlAverage

但这会给我一个错误

1 个答案:

答案 0 :(得分:1)

首先-强烈建议我们应始终避免对日期时间列执行字符串操作。

您可以尝试通过将concat放在::TIME关键字前面的右括号中来将interpolate表达式强制转换为TIME。但这仍然不算什么。

尝试下面查询的第三个表达式(当然,WITH子句只是为了演示其工作原理)。请注意,由于函数在时间戳记::(在Vertica中使用)是CAST运算符,因此我先转换为时间戳,然后又转换为时间:

WITH a ( time1            , time2 ) AS (
  SELECT '12:12:12'::time , '00:00:56'::time
)
SELECT
  time1
, time2
, TIMESTAMPADD(
  -- 2. add the seconds contained in time2
    SECOND        -- the unit to add to a timestamp meant by next param
  , SECOND(time2) -- the "second" part of time2 as Integer
  , TIMESTAMP_TRUNC(time1::TIMESTAMP,'mi')
    -- 1. cast time1 to timestamp, then truncate to "minute" precision
  )::TIME
  -- 3. cast back to TIME type
FROM a
;

结果:

time1   |time2   |timestampadd
12:12:12|00:00:56|12:12:56