我正在重构几年前由其他人编写的 Java 程序,无法与他们联系以了解有关 SQL / 数据库的任何信息,但是此查询不起作用(有两个查询时不返回任何结果分开做)。我知道在没有更多信息的情况下询问很烦人,但目前我真的没有太多选择。
"SELECT " + CLMHDR + ".POLBRC, "
+ CLMHDR + ".POLTYC, " + CLMHDR + ".POLNOC," + CLMHDR + ".CLTKYC, "
+ POLHDR + ".INCPTP FROM "+ CLMHDR +
"INNER JOIN " + POLHDR + " ON " + CLMHDR + ".CLTKYC = " + POLHDR+ ".CLTKYP"
+ " WHERE POLNOC = "+ polnocSearch
+ " AND POLBRC = '" + polbrcSearch + "'"
+ " AND POLTYC = '" + poltycSearch + "'"
+ " AND DATRPC <= " + claimDate
+ " GROUP BY POLBRC, POLTYC, POLNOC, CLTKYC"
表 CMLHDR 和 POLHDR 确实包含它所引用的列,并且 CLTKYC 和 CLTKYP 是每个表中的键。对不起这些可怕的名字,我们也被 RPG 困住了。
编辑:起作用的是:
"SELECT POLBRC, POLTYC, POLNOC, CLTKYC FROM "+ CLMHDR
+ " WHERE POLNOC = "+ polnocSearch
+ " AND POLBRC = '" + polbrcSeach + "'"
+ " AND POLTYC = '" + poltycSearch + "'"
+ " AND DATRPC <= " + claimDate
+ " GROUP BY POLBRC, POLTYC, POLNOC, CLTKYC"
其次是:
"SELECT INCPTP, TRMTHP FROM "+ POLHDR + " WHERE POLNOP = "+ polnocSearch
+ " AND POLBRP = '"+ polbrcSearch+ "' AND POLTYP = '"+ poltycSearch + "'"
但我真的更希望一次返回所有数据。