[英]Select order by random() Query not working in Java
我正在我的存儲庫中使用查詢,我試圖從表中選擇10個隨機問題。 但我得到這個錯誤ASC或DESC預期得到'('我不知道為什么
@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);
首先,按1,2,3或任何數字排序意味着按相應位置的列排序; 如果您只選擇一列(在您的情況下為q
),您將只能按此排序(盡管可能在舊版本中有效)。
然后,按臨時值排序的正確語法是order by rand()
這對我有用:
@Query ( value = "select * from question q where q.chapitre_id=:id order
by rand() limit 10", nativeQuery = true)
Question[] findQuestionsByChapitre(@Param("id") Long id);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.