我有此查詢與WrappedBean:HQL:列必須出現在GROUP BY或選擇
buffer.append("SELECT new myPackage.WrappedBean(E.debitant.id, E.dateCalcul, E.verse, E.incidenceReprise, E.soldeSoumission) ");
buffer.append("FROM " + getEntityClassName() + " E ");
buffer.append("LEFT JOIN E.debitant DT ");
buffer.append("WHERE E.debitant.id = :idDebitant ");
buffer.append("AND YEAR(E.dateCalcul) = :year ");
buffer.append("GROUP BY E.debitant.id");
hqlQuery = session.createQuery(buffer.toString());
hqlQuery.setInteger("idDebitant", idDebitant);
hqlQuery.setInteger("year", year);
我創建WrappedBean返回索姆列使用GROUP BY。
當我試着執行它時,我得到這個錯誤:
org.postgresql.util.PSQLException:ERREUR:列«complement0_.date_calcul»必須出現在GROUP BY子句或者必須選擇使用(我翻譯從法國誤差)
我的Postgres的查詢犯規包含date_calcul在GROUP BY。
另一個問題,我的查詢中我也一直這樣:
SUM(CASE WHEN YEAR(dateCalcul)[email protected] AND verse>0 THEN verse ELSE 0 END)
我知道在HQL,我們不能做的情況下,當在選擇,因爲這個原因,我不添加SUM列詩
什麼我已經忘了嗎?
這是我在Postgres的查詢: '選擇id_debitant,dateCalcul,詩歌,soldeSoumission FROM calc_cdr WHERE id_debitant = someValue中 和Year(dateCalcul)= @PECAnnee GROUP BY id_debitant' – Pasja95
@ Pasja95好,Postgres也應該抱怨這個查詢。另外,查詢中包含'dateCalcul'但不是'date_calcul'。如果前者是正確的名稱,然後看看你的映射,因爲這是最有可能是錯誤的。 – Thomas