2014-04-09 161 views
-1

我的SQL是查詢春季儲存庫

SELECT formid 
    FROM (SELECT formid, COUNT(*) cc FROM formevalremarks 
       WHERE completed='Y' GROUP BY formid) 
WHERE (formid, cc) IN 
       (SELECT formid, COUNT(*) dd FROM formevalremarks GROUP BY formid) 

如何在春天回購它寫在@Query ????


我試過..

@Query("select f.formId from (SELECT f.formId ,COUNT(*) f.cc FROM FormEvalRemarks f WHERE f.completed='Y' GROUP BY f.formId) where (f.formId ,f.cc) in (SELECT f.formId ,COUNT(*) f.dd FROM FormEvalRemarks f GROUP BY f.formId)")
List<Long> complForms()
;

它越來越... org.springframework.beans.factory.BeanCreationException

+1

你試過了什麼? – Rembo

+0

通過啓用'nativeQuery = true',您可以在'@Query(custome SQL)'中使用本機查詢,但會鬆散數據庫。 – Rembo

回答

0

我在早晨的例外,做正確的做法是。

@Query("select f.formId as formID from 
     (SELECT f.formId ,COUNT(*) f.cc FROM FormEvalRemarks f WHERE f.completed='Y' GROUP BY f.formId) where (f.formId ,f.cc) in (SELECT f.formId ,COUNT(*) f.dd FROM FormEvalRemarks f GROUP BY f.formId)" , native=true) 
    List<Long> methodToExecute(); 

如果這不起作用嘗試使用。

@NamedNativeQuery(name="MyQuery", query="select f.formId as formID from (SELECT f.formId ,COUNT(*) f.cc FROM FormEvalRemarks f WHERE f.completed='Y' GROUP BY f.formId) where (f.formId ,f.cc) in (SELECT f.formId ,COUNT(*) f.dd FROM FormEvalRemarks f GROUP BY f.formId)", resultSetMapping = "MyMapper") 

@SqlResultSetMapping(name="MyMapper", 
    columns={ 
     @ColumnResult(name="formID") 
    } 
) 

@Query(name="MyQuery" , native=true) 
List<Object> methodToExecute();