简体   繁体   English

如何比较两个数据集以检查其他数据集中不存在的缺失行?

[英]How to compare two datasets to check for missing rows which don't exist in the other dataset?

I have built a method which takes two datasets: dataset1 and retirementSimpleData . 我建立了一个方法,该方法需要两个数据集: dataset1retirementSimpleData It matches the two datasets based on a primary key/number, defined as cnum , in the code below. 它在下面的代码中基于定义为cnum的主键/数字匹配两个数据集。 I wanted to return the value of the difference between the getAssets value and the getSums value, and this is working, except for one little problem. 我想要返回getAssets值和getSums值之间的差值,并且此方法有效,除了一个小问题。

Some of the cnums that exist in dataset1 don't exist in retirementSimpleData . 一些存在于数据集1的cnums的不retirementSimpleData存在。 Similarly, some cnums which may exist in retirementSimpleData may not exist in dataset1 . 同样,这可能在retirementSimpleData存在着一些cnums可能无法在数据集1存在。 This is resulting in no data being returned for that cnum . 这导致没有为该cnum返回任何数据。

I would like to implement two passes at the end which check in one direction to see if I missed anything. 我想在末尾实现两次通过,以检查一个方向是否丢失了任何东西。 The second pass would check in the opposite direction. 第二遍将以相反的方向进行检查。 However, not sure how I would go about implementing this. 但是,不确定如何实现此目标。

 public void getReportData(int index) {

        String date1 = Util.dateTimeToShortString(reportDate);
        String date2 = reportDao.getPreviousRetirementDate(date1);

        List<SurveyCompareAssetsCheckData> dataset1 = reportDao.getSurveyCheckCompareAssetsData(date1);

        List<RetSurveyAssets> retirementSimpleData = reportDao.findRetSurveyByDate(date1);

        for (SurveyCompareAssetsCheckData surveyCompareAssetsCheckData : dataset1) {
            for (RetSurveyAssets surveyCompareAssetsCheckData2 : retirementSimpleData) {
                if (surveyCompareAssetsCheckData.getCnum() == surveyCompareAssetsCheckData2.getCnum()) {
                    surveyCompareAssetsCheckData.setRetirementsimple(surveyCompareAssetsCheckData2.getSums());
                    surveyCompareAssetsCheckData.setDifference(surveyCompareAssetsCheckData.getAssets() - surveyCompareAssetsCheckData2.getSums());

Caveat: dataset1 and retirementSimpledata both use existing SQL pulls which I am not allowed to touch, otherwise I would have simply defined new SQL for these methods in my "DAOImpl." 注意: dataset1retirementSimpledata都使用现有的SQL pull,我不允许接触这些ull,否则我将在“ DAOImpl”中为这些方法简单地定义新的SQL。 Therefore, I have to work with the data I am getting, and programmatically check for this. 因此,我必须处理要获取的数据,并以编程方式对此进行检查。

Below, is the report which is being generated with my code. 下面是使用我的代码生成的报告。 As you can see, I am ending up with zeros, which is showing the difference (incorrectly) as zeros, because Cnum #45, in this example simply doesn't exist in the second dataset ( retirementSimpleData ) 正如你所看到的,我结束了零,这正显示出差异(错误地)为零,因为CNUM#45,在这个例子中根本就不在第二个数据集存在(retirementSimpleData) 在此处输入图片说明

What is the datatype of Cnum, if it is int then default value is Zero. Cnum的数据类型是什么,如果为int则默认值为零。

You have to add else-if condition to check for example: 您必须添加else-if条件进行检查,例如:

else if (surveyCompareAssetsCheckData2.getCnum()== 0){

-------- logic here --------------------

}
else if (surveyCompareAssetsCheckData.getCnum() ==0){

----------logic here -----------

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM