java - 如何在 java 中创建具有来自 3 个表的记录的数据结构?

标签 java sql oracle data-structures oracle11g

如何在 java 中创建具有来自 3 个表的记录的数据结构?

查询/记录总数。

select * from TRANSACTION where workitemid = '104854'; (1 Record)
select * from WHT where workitemid = '104854'; (1 Record)
select * from FX where workitemid = '104854'; (2 Record)

JAVA 中的数据结构。

PSRResponseReportDTO{
    String workitemid;

    public PSRResponseReportDTO() {
        this.fxDetail = new HashSet<PSRResponseReportDTO>();        
        this.whtDetails = new HashSet<PSRResponseReportDTO>();
        this.invoiceDetails = new HashSet<PSRResponseReportDTO>();
    }
}

查询

select ptw.workitemid
       , pttd.workitemid   as PAY_TXN_TAX_DETAILS_WORK_ID 
       , ptsi.workitemid   as pay_txn_supp_inf_work_id
from TRANSACTION ptw
     , WHT pttd
     , FX ptsi
where ptw.workitemid = pttd.workitemid (+)
AND ptw.workitemid =  ptsi.workitemid (+)
AND ptw.workitemid = '104854'
order by ptw.workitemid;

该表没有主键,只有外键。休耕获得的数据的一个例子。问题是如何识别 Fx 有两行,WHT 有一行?

查询结果:

|  PTW   |   WHT   |   FX   | PTW.COLUMN1 | FX_COLUMN1 | WHT_COLUMN 1 |
+--------+---------+--------+-------------+------------+--------------+
| 104854 |  104854 | 104854 |      1      |     2      |      3       |
| 104854 |  104854 | 104854 |      1      |     2      |      3       |

最佳答案

您可以使用 count() a 获取放置在子查询中的 WHTFX 的数量。

select t1.workitemid, count(1) as ptwNumRows
    , (select count(1) ct from WHT t2 where t2.workitemid = t1.workitemid) as pttdNumRows
    , (select count(1) ct from FX t3 where t3.workitemid = t1.workitemid)   as ptsiNumRows
from TRANSACTION t1
where t1.workitemid = '104854'
order by t1.workitemid;

参见 dbfiddle

关于java - 如何在 java 中创建具有来自 3 个表的记录的数据结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58831852/

相关文章:

java - Maven 在 Google App Engine 上自动部署

java - CAS编程的优缺点

java - 无论如何要找出当前正在使用该对象的线程数?

sql - 如何从 SQL Server 创建可移植插入?

mysql - 将 2 个具有不同列数的 select 语句组合在一起,其中第一个语句已使用 JOIN

sql-server - sql server 文件流在oracle数据库中等效

java - 将数组索引与字符串进行比较?

mysql - 选择查询 char numeric id 按 desc 排序

java - JDBC QueryTimeout 仅适用于某些供应商

oracle - 我可以手动更改Oracle的imp工具创建的转储文件吗?