我收到以下错误:
无法执行查询; SQL [select DFBOGARM,sum(KVANTUM1) 作为KSTANTUM1,(sum(DSTOMK)* 1000 / sum(KVANTUM1))作为DSTOMK, (总和(DSTAKK)* 1000 /总和(KVANTUMAKK))作为DSTAKK来自 NHODATA.ERHDSTV1其中DFSALVAR在(52,55)组由DFBOGARM命令 DFBOGARM];嵌套异常是 org.hibernate.exception.SQLGrammarException:无法执行查询
引起:org.hibernate.exception.SQLGrammarException:不能 执行查询
引起:com.ibm.as400.access.AS400JDBCSQLSyntaxErrorException:An 检测到未定义的列名称。
查询实施:
public interface DistributionRepository extends JpaRepository<ERHDSTV1, Long> {
@Query(value="select "
+ " DFBOGARM, "
+ " sum(KVANTUM1) as KVANTUM1, "
+ " (sum(DSTOMK) * 1000 / sum(KVANTUM1)) as DSTOMK, "
+ " (sum(DSTAKK) * 1000 / sum(KVANTUMAKK)) as DSTAKK "
+ "from NHODATA.ERHDSTV1 "
+ "where DFSALVAR in(52, 55) "
+ "group by DFBOGARM "
+ "order by DFBOGARM", nativeQuery = true)
List<ERHDSTV1> findSummedValuesFor52and55();}
实体类:
@Entity
@IdClass(ERHDSTV1Id.class)
@Table(name = "ERHDSTV1")
@Data
public class ERHDSTV1 {
@Id
@Column(name = "DFBOGARM")
private String yearMonth;
@Id
@Column(name = "DFSALVAR")
private Long salesType;
@Column(name = "KVANTUM1")
private Long volumeOne;
@Column(name = "DSTOMK")
private Long distributionCosts;
@Column(name = "DSTMDN")
private Long distributionMedian;
@Column(name = "KVANTUMAKK")
private Long volumeAccumulated;
@Column(name = "DSTAKK")
private Long distributionAccumulated;
@Column(name = "DSTMNDAKK")
private Long distributionMedianAccumulated;
}
从sql工具执行时,错误消息中的查询执行完美。
和标题是:DFBOGARM,KVANTUM1,DSTOMK,DSTAKK
答案 0 :(得分:3)
好的,所以错误是我必须为上面的每一列选择值。
这意味着我做了这样的查询:
display: block;
并且有效。