sql - DB2,SQL 下一个代码 = 修改描述 将实际 id 传递给子选择
问题描述
你好我还在学习sql,我有新的挑战。
如果代码 AMD 的描述由关键字开始,例如 /delete,我必须在最后一行删除后删除短语并插入描述。
例如对于代码 AMD 中的 transaction1 有关键字 delete 和 ab 所以我想删除 ab 所以如果步骤 AMD001 是最后一个结果将是 cdefgh。
完整示例(ISS 始终是第一步,在步骤 AMD 中发生变化)
交易编号 | 代码 | 描述 |
---|---|---|
1 | ISS001 | abcdefgh |
1 | AMD001 | 删除/ab |
1 | AMD002 | 删除/c |
1 | AMD003 | 删除/天 |
1 | AMD004 | 添加/电子 |
输出交易=1 描述= efghe。
我尝试使用子句案例。
with data as
(
select transaction_id,description from table where code=ISS001
),
data1 as (
select transaction_id,
Case
when code=AMD001 and description like 'ADD/%' then data.description || substr(table.descrption, 4, length(table.descrption-4))
when code=AMDD001 and description like 'DELETE/%' ........
end as first
from ......
),
data2 as
(
select
transaction_id,
Case
when code=AMD002 and description like 'delete/%' then (select first from data1 where data1.transaction_id =data_2.transaction_id ) || substr(table.descrption, 4, length(table.descrption-4))
when code=AMDD002 and description like 'DELETE/%' ........
end as second from.....
)
select * from data2
我在将实际 transaction_id 传输到数据 2 上的子选择时遇到问题
(
select first from data1 where data1.transaction_id =data_2.transaction_id
)。
它可能吗?你能帮助我吗 ?任何提示?
解决方案
推荐阅读
- lua - wibar wibox 对齐问题。将配置更改回正常后,部分不再与右侧对齐
- api - 如何使用来自后端服务的 MS Graph API 在 MS Teams 日历中创建事件
- haskell - 如何为受 MonadReader 和 MonadIO 约束的函数修复缺少的 IO 实例?
- uwp - 如何设置 UWP 应用的默认语言?
- swift - 在 Swift 4.2 中,后台获取每秒都在工作
- python - 在 Discord.py 中的嵌入中发送 gif
- fibonacci - 定义一个函数:斐波那契数列
- c# - C# WebSocketClient 总是接收垃圾数据
- python - Peewee 一对一连接
- aws-lambda - 我可以通过 API 网关通过 Lambda 调用 AWS Cognito 吗?