【发布时间】:2021-04-13 16:41:55
【问题描述】:
我正在尝试声明变量并在我的 sql 查询中使用它,如下所示,但它给了我错误:
-- this will get the the timestamp in seconds
DECLARE @startTimeStamp bigint = cast(DATEDIFF(s, '1970-01-01 00:00:00.000', '2016-12-09 16:22:17.897' ) as bigint)
DECLARE @endTimeStamp bigint = cast(DATEDIFF(s, '1970-01-01 00:00:00.000', '2016-12-10 16:22:17.897' ) as bigint)
-- my query.
SELECT processId,
houroftheday,
minuteofhour,
listagg(clientId, ',') within group (order by minuteofhour) as clientIds,
count(*) as psg
FROM data.process
where kite = 'BULLS'
and code is null
and timestampinepochsecond >= @startTimeStamp AND timestampinepochsecond < @endTimeStamp
group by 1, 2, 3
我读了它here,因为这是不可能的,所以我怎样才能重写我的上述查询,以便它可以正常工作?我尝试了他们的示例,但在转换时遇到了问题。
以下是我尝试过的,但出现语法错误:
CREATE TEMP TABLE tmp_variables AS SELECT
cast(DATEDIFF(s, '1970-01-01 00:00:00.000', '2016-12-09 16:22:17.897' ) as bigint) AS StartDate,
cast(DATEDIFF(s, '1970-01-01 00:00:00.000', '2016-12-10 16:22:17.897' ) as bigint) AS EndDate;
这是我的demo,它给出了错误:
【问题讨论】:
-
请发布您遇到的错误。
-
这是我的demo
标签: sql amazon-web-services amazon-redshift