Teradata:在满足条件时,是否可以忽略OLAP分区中的行,并且在未达成时仍将值传递给时值?
我正在根据客户以前的订单对数据进行分区,因此,如果客户以前在其帐户中添加了服务(他们有服务或不服务),我希望该价值将其带到下一行中对于所有订单状态如何,但我不希望通过下一个订单计算被取消的订单服务,我想跳过这些行并从先前完成的订单中降低价值。有人知道这是否可能吗?如果我按子句将字段添加到分区中,则将按订单状态进行分区,而不是从上一个完成的订单中报告订单状态。
(
Sum
(
SUBSCR1_ORD
)
Over
(
PARTITION BY ACCT_NO
ORDER BY ORDER_DATE
ROWS BETWEEN 1 Preceding AND 1 Preceding
)
)
AS EXISTING_SVC1
列的结果的样子,
acct_no | order_date | order_status | subscr1_ord | subscr2_ord | subscr2_ord_svc1 | 这就是 |
---|---|---|---|---|---|---|
我希望根据subcr1_ord列中活动的现有_svc | order_status | ercest_svc1 | order_date | subscr1_ord | 1234 | 在 |
ercest_svc2 | 并 /2022 | 取消 | -1 | 1 | 1 | 0 |
1234 | 6/7/2022 | 完成 | NULL | 1 | 1 | 0 |
I'm partitioning data based on a customers previous order, so if the customer previously added a service to their account (they either have the service or they don't), I want that value to carry down to the next row for that customer for all orders regardless of the order status, but I don't want canceled order services to be calculated with the next order, I want to skip those rows and bring down the value from the previously completed order. Does anyone know if this is possible? If I add the field into the Partition By clause, it'll partition by order status instead of reporting the order status from the previous completed order.
(
Sum
(
SUBSCR1_ORD
)
Over
(
PARTITION BY ACCT_NO
ORDER BY ORDER_DATE
ROWS BETWEEN 1 Preceding AND 1 Preceding
)
)
AS EXISTING_SVC1
This is what I'd want the results to look like for the EXISTING_SVC columns based on activity in the SUBSCR1_ORD column with special handing on ORDER_STATUS
ACCT_NO | ORDER_DATE | ORDER_STATUS | SUBSCR1_ORD | SUBSCR2_ORD | EXISTING_SVC1 | EXISTING_SVC2 |
---|---|---|---|---|---|---|
1234 | 6/5/2022 | Complete | 1 | null | 0 | 0 |
1234 | 6/6/2022 | Canceled | -1 | 1 | 1 | 0 |
1234 | 6/7/2022 | Complete | null | 1 | 1 | 0 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将lag与忽略nulls和案例表达式使用以“下拉”先前的值。
Use LAG with IGNORE NULLS and a CASE expression to "pull down" the prior value.