我正在从事某个项目。我有一个JPA查询,我想给我一个结果集,但结果必须排除与另一个表中的某些数据匹配的条目,因此使用NOT IN。我的查询如下:
String sql = "SELECT DISTINCT(tia.voucherId) As Voucher, "
+ "e.farmId.name As Farm, CONCAT(e.farmId.farmerId.firstName, ' ', e.farmId.farmerId.lastName) AS Farmer,"
+ " tia.seasonId.name Season, e.farmingActivityId.name As FarmingActivity FROM Enrollment e,"
+ " TemporaryInputsAllocated tia where e.farmId = tia.farmId"
+ " AND tia.voucherId NOT IN (SELECT DISTINCT(ia.voucherId) from InputsAllocated ia )";
当我运行我的代码时,我收到错误:
ERROR controllers.ContractApplicationController - java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing the query [SELECT DISTINCT(tia.voucherId) As Voucher, e.farmId.name As Farm, CONCAT(e.farmId.farmerId.firstName, ' ', e.farmId.farmerId.lastName) AS Farmer, tia.seasonId.name Season, e.farmingActivityId.name As FarmingActivity FROM Enrollment e, TemporaryInputsAllocated tia where e.farmId = tia.farmId AND tia.voucherId NOT IN (SELECT DISTINCT(ia.voucherId) from InputsAllocated ia )], line 1, column 333: unexpected token [(].
Internal Exception: NoViableAltException(83@[1302:1: simpleSelectExpression returns [Object node] : (n= singleValuedPathExpression | n= aggregateExpression | n= variableAccessOrTypeConstant );])