2017-04-10 114 views
1

我在我的存儲庫中使用查詢,我試圖從表中選擇10個隨機問題。但我得到這個錯誤 ASC或DESC預期得到了「(」 ,我不知道爲什麼按隨機順序選擇()查詢不工作在Java

@Query (value = "select q from Question q where q.chapitre_id=:id order by 
random() limit 10", nativeQuery = true) 
List<Question> findQuestionsByChapitre(@Param("id") Long id); 
+0

嘗試蘭特(),而不是隨機的() –

+0

沒有工作或者 –

+0

你不應該使用'限10'這裏像'Oracle'不支持幾個數據庫儘管許多支持。我建議你嘗試使用'Page'和'Pageable'接口 – harshavmb

回答

0

這是爲我工作:

@Query (value = "select * from question q where q.chapitre_id=:id order 
    by rand() limit 10", nativeQuery = true) 
    Question[] findQuestionsByChapitre(@Param("id") Long id); 
0

首先,由1訂貨,2,3或任何數量由列方式訂購相應的位置;如果只選擇(在你的情況q)一列,你將能夠僅通過該訂單(它可以在舊版本的工作,雖然)

然後,通過一個偶然值的正確語法排序。是order by rand()

+0

rand()不適用於我 –

+1

還有同樣的錯誤? –

+0

是相同的錯誤ASC或DESC預計得到'(' –