如何在 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 获取放置在子查询中的 WHT
和 FX
的数量。
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/