【发布时间】:2020-10-01 19:21:13
【问题描述】:
抱歉,如果这个问题已经得到解答,我查看了但找不到我正在寻找的确切内容。我有 2 组查询
- 查询 1:借记通知单查询我想为每个 Account_number 返回 1 个借记通知单(没有具体的偏好)
- 查询 2:贷项通知单查询我想为每个 Account_number 返回 1 个贷项通知单(没有具体的偏好),匹配查询 1 和 2 按账号并在列而不是行中显示结果。
第一个问题:我需要从查询 1 中限制每个帐户的借方通知单和从查询 2 中的每个帐户的贷方通知单。然后通过帐号匹配查询 1 和查询 2,并在列中返回结果。所需的结果显示在下面的屏幕截图中。
查询 #1 借记通知单查询:
Select distinct
hca.account_number, hcsu.attribute8, hcsu.attribute9,
apsa.amount_due_remaining debit_memo_amount, apsa.customer_trx_id, rcta.trx_number
from
hz_cust_accounts hca, hz_cust_acct_sites_all hcas, hz_cust_site_uses_all hcsu, ra_customer_trx_all rcta, ar_payment_schedules_all apsa, manar.man_om_consignments mac
where
1 = 1
and hca.cust_account_id = hcas.cust_account_id
and hca.cust_account_id = rcta.bill_to_customer_id
and rcta.customer_trx_id = apsa.customer_trx_id
and hcas.cust_acct_site_id = hcsu.cust_acct_site_id
and hcsu.SITE_USE_CODE = 'BILL_TO'
and hcsu.status = 'A'
and ((apsa.amount_due_remaining > 0 and hcsu.attribute9 = 'CUSTOMER REFUND'))
and mac.CONSIGNMENT_ID = rcta.attribute2
order by 2, 1, 5;
查询 #2 贷项凭单查询:
Select distinct
hca.account_number, hcsu.attribute8, hcsu.attribute9,
apsa.amount_due_remaining credit_memo_amount, apsa.customer_trx_id, rcta.trx_number
from
hz_cust_accounts hca, hz_cust_acct_sites_all hcas, hz_cust_site_uses_all hcsu, ra_customer_trx_all rcta, ar_payment_schedules_all apsa, manar.man_om_consignments mac
where
1 = 1
and hca.cust_account_id = hcas.cust_account_id
and hca.cust_account_id = rcta.bill_to_customer_id
and rcta.customer_trx_id = apsa.customer_trx_id
and hcas.cust_acct_site_id = hcsu.cust_acct_site_id
and hcsu.SITE_USE_CODE = 'BILL_TO'
and hcsu.status = 'A'
and ((apsa.amount_due_remaining < 0 and hcsu.attribute9= 'CUSTOMER REFUND'))
and mac.CONSIGNMENT_ID = rcta.attribute2
order by
2, 1 , 5;
想要的结果:
【问题讨论】:
-
欢迎来到 Stack Overflow。请使用标签正下方的
edit按钮编辑您的问题,并说明哪个字段包含借方/贷方金额。我看到在WHERE子句的倒数第二个比较中,唯一的区别是<与>,但是在您的字段列表中,我不知道哪个包含贷方/借方金额。会是attribute8吗?attribute9?amount_due_remaining?另外,请不要像图片一样发布代码或数据 - 使用格式化文本,以便人们可以将其复制出来并使用它。坦率地说,我对重新输入您的数据没有兴趣。谢谢。 -
Bad habits to kick : using old-style JOINs - 旧式 逗号分隔的表格列表 样式已替换为 ANSI 中的 proper ANSI
JOIN语法-92 SQL 标准(25 多年前),不鼓励使用它 -
我已经编辑了我的问题,指出哪个是贷项通知单查询和借项通知单查询,字段名称正确(amount_due_remaining)
标签: oracle pivot oracle-sqldeveloper transform oracle12c