【发布时间】:2021-09-15 10:14:22
【问题描述】:
我在我的 redshift 集群上有一个 SQL 查询:-
select
a.employee_id as "Employee ID",
a.transaction_id as "Transaction ID",
CONVERT_TIMEZONE('US/Pacific',a.created_datetime) as "Created Date Time",
a.status as Status,
a.pay_period_start as "Pay Period Start Date",
a.pay_period_end as "Pay Period End Date",
a.currency as "Payment Currency",
a.error_code as "Error Code",
CONVERT_TIMEZONE('US/Pacific',a.payment_datetime) as "Payment Date Time",
case when CONVERT_TIMEZONE('US/Pacific',a.payment_datetime) is null then null
else datediff(minutes,CONVERT_TIMEZONE('US/Pacific',a.created_datetime),CONVERT_TIMEZONE('US/Pacific',a.payment_datetime)) end as Minus_To_Pay,
CONVERT_TIMEZONE('US/Pacific',a.update_datetime) as "Update Date Time",
a.amount as "Withdraws amount",
b.ngr
from (
select a.*
from transaction_service_internal.withdrawal_transaction a
where a.update_time = (select max(update_time) from transaction_service_internal.withdrawal_transaction b where b.transaction_id=a.transaction_id)
) a
inner join
(
select k.*
from transaction_service_internal.transaction_snapshot k
where nvl(k.update_time, k.created_timestamp) = (select max(nvl(k1.update_time, k1.created_timestamp)) from transaction_service_internal.transaction_snapshot k1 where k.transaction_id=k1.transaction_id)
) b
on a.transaction_id=b.transaction_id
这里返回的条目包含截至目前(当前时间)的付款日期时间的所有事件。我想要前一天的所有条目(基本付款日期时间)。例如,如果现在的时间是 PST 时区的 7 月 2 日,则查询应返回付款日期时间仅为 7 月 1 日的记录。有人可以帮忙吗?
【问题讨论】:
-
您知道如何编写这样的查询,但不知道如何在其上放置 WHERE 子句?
-
嘿@CaiusJard,其实我没有写这个。它出现在我们的一份快速景点报告中。尽管如此,我知道如何放置一个 where 子句,但我如何设法将它放置在当前日期 - 一种东西?
-
你读过documentation page吗?
-
它是什么数据库? MySQL PG
-
如果你用Redshift,那为什么还要加上postgres和MySQL标签呢?
标签: sql amazon-web-services amazon-redshift