【问题标题】:How can I create data structure in java having records from 3 tables?java - 如何在具有3个表的记录的java中创建数据结构?
【发布时间】:2020-03-08 22:34:13
【问题描述】:

如何在 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;

表没有主键,只有外键。 Fallows 获得的数据的示例。问题是如何确定 Fx 有两行,WHT 有一行?

查询结果:

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

【问题讨论】:

    标签: java sql oracle data-structures oracle11g


    【解决方案1】:

    您可以使用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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-05
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 2017-01-10
      • 1970-01-01
      相关资源
      最近更新 更多