【问题标题】:Syntax error: Expected ")" but got identifier "ciclos" at [62:23]语法错误:应为“)”,但在 [62:23] 获得标识符“ciclos”
【发布时间】:2020-10-28 14:50:42
【问题描述】:

我尝试像这样进行 2 次转换:

select TIME_DIFF(TIME ciclos.hora_inicio, TIME ciclos.hora_fin, MINUTE) as diferencia from 
  (select 
     split(split(document_name, '/ciclos/')[OFFSET(1)], '/eventos/')[OFFSET(0)] as id_ciclo, 
     REPLACE(JSON_EXTRACT(data, '$.codigo'), '"', '') as codigo, 
     REPLACE(JSON_EXTRACT(data, '$.hora_fin'), '"', '') as hora_fin,  
     REPLACE(JSON_EXTRACT(data, '$.hora_inicio'), '"', '') as hora_inicio,  
   from `fleetpas-34c3d.eventos.flet_raw_changelog`
   where document_id = 'XPr9cyA9yn3U51rvRANQ'
  ) as ciclos

https://roboquery.com/app/syntax-time-diff-function-bigquery

【问题讨论】:

  • 您的查询中的位置 [62:23] 是什么?
  • [62:23] 选择 TIME_DIFF(TIME ciclos.hora_inicio, TIME ciclos.hora_fin, MINUTE) 作为 direncia from
  • 这样工作正常:选择 TIME_DIFF(TIME '06:45:18', TIME '06:39:57', MINUTE) 作为差异来自
  • 暂时忽略你的错误,还请注意TIME_DIFF()函数中的顺序。 TIME_DIFF(a,b,interval) 是 b-a。你的查询的编写方式,我假设你有它倒退。

标签: google-bigquery


【解决方案1】:

改为使用以下(BigQuery 标准 SQL)

TIME_DIFF(PARSE_TIME('%T', ciclos.hora_inicio), PARSE_TIME('%T', ciclos.hora_fin), MINUTE)    

注意:假设(根据您的 cmets)hora_inicio 和 hora_fin 的格式类似于 '06:45:18'

【讨论】:

  • TIME_DIFF(CAST(REPLACE(JSON_EXTRACT(evento.data, '$.hora_fin'), '"', '') AS TIME),CAST(REPLACE(JSON_EXTRACT(evento.data, '$ .hora_inicio'), '"', '') AS TIME), MINUTE) as diferencia
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-04
  • 2015-06-15
  • 1970-01-01
相关资源
最近更新 更多