到目前为止SQL的时间戳

2 sql sql-server timestamp sql-server-2008 google-bigquery

我需要像这样更改时间戳:

1519152103659000     
1519152113786000     
1519152118754001     
1519152118972002     
1519152119026003
Run Code Online (Sandbox Code Playgroud)

在sql中的日期.这个时间戳是我表中的一列.我使用timestamp命令,但我有一个错误:

错误:参数类型的函数TIMESTAMP没有匹配的签名:INT64.支持的签名:TIMESTAMP(STRING,[STRING]); TIMESTAMP(日期,[STRING]); TIMESTAMP(DATETIME,[STRING])在[2:1]

谢谢!!

Mik*_*ant 6

下面的示例适用于BigQuery StandardSQL

#standardSQL
WITH t AS (
  SELECT 1519152103659000 AS ts UNION ALL
  SELECT 1519152113786000 UNION ALL
  SELECT 1519152118754001 UNION ALL
  SELECT 1519152118972002 UNION ALL
  SELECT 1519152119026003 
)
SELECT 
  ts AS timestamp_in_microseconds_as_int64,  
  TIMESTAMP_MICROS(ts) AS timestamp_as_timestamp,
  DATE(TIMESTAMP_MICROS(ts)) AS dt
FROM t  
Run Code Online (Sandbox Code Playgroud)

结果为

Row timestamp_in_microseconds_as_int64  timestamp_as_timestamp          dt   
1   1519152103659000                    2018-02-20 18:41:43.659 UTC     2018-02-20   
2   1519152113786000                    2018-02-20 18:41:53.786 UTC     2018-02-20   
3   1519152118754001                    2018-02-20 18:41:58.754 UTC     2018-02-20   
4   1519152118972002                    2018-02-20 18:41:58.972 UTC     2018-02-20   
5   1519152119026003                    2018-02-20 18:41:59.026 UTC     2018-02-20   
Run Code Online (Sandbox Code Playgroud)