Teradata SQL 条件聚合
我有下表,其中包含一些客户一个月的数据,我需要根据每列值的条件聚合该表,
条件
- 如果客户的
稳定性
有> = 2 “非常不稳定”状态则在Value_1
中返回 1 else 0 - 如果客户在整个月内至少有一条值为
1
的记录,则返回 1 else
|Cust_ID|Date |Stability |Value_1|
|-------+--------+--------------+-------|
|123 |3/1/2022|Unstable |1 |
|123 |3/2/2022|Very Unstable |0 |
|123 |3/3/2022|Stable |1 |
|123 |3/4/2022|Ver Stable |NULL |
|123 |3/5/2022|Unstable |NULL |
|123 |3/6/2022|Very Unstable |0 |
|123 |3/7/2022|Unstable |0 |
|123 |3/8/2022|Very Unstable |0 |
|… |… |… |… |
|123 |3/31/2022|Very Unstable|0 |
0结果表如下:
|Cust_ID|Stability|Value_1|
|-------+---------+-------|
|123 |1 |1 |
I have the below table with data for one month for some customers, and I need to aggregate this table based on conditions for the values of every column,
The conditions
- If the customer's
stability
have >= 2 of "Very Unstable" status then return 1 else 0 - In
Value_1
if the customer has at least one record with the value:1
along the entire month then return 1 else 0
|Cust_ID|Date |Stability |Value_1|
|-------+--------+--------------+-------|
|123 |3/1/2022|Unstable |1 |
|123 |3/2/2022|Very Unstable |0 |
|123 |3/3/2022|Stable |1 |
|123 |3/4/2022|Ver Stable |NULL |
|123 |3/5/2022|Unstable |NULL |
|123 |3/6/2022|Very Unstable |0 |
|123 |3/7/2022|Unstable |0 |
|123 |3/8/2022|Very Unstable |0 |
|… |… |… |… |
|123 |3/31/2022|Very Unstable|0 |
to be the result table like that:
|Cust_ID|Stability|Value_1|
|-------+---------+-------|
|123 |1 |1 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎与您的描述相符:
This seems to match your description: