JPA:如何获取不同列的记录:

时间:2014-04-01 10:07:03

标签: java mysql sql hibernate jpa

如何编写查询以获取一列中不同的记录和另一列中的desc顺序。

我可以使用以下语句获取记录。

  select * from
 (select * from t1 
  where id=14 
  order by ttimestamp desc) as h 
  group by hnumber 
  order by ttimestamp desc

但是当我在JPA中尝试相同的时候。

  SELECT m from 
  (SELECT m from t1 m 
   WHERE m.user = :user 
   ORDER BY m.tTimestamp DESC) as h 
  GROUP BY m.hNumber 
  ORDER BY m.tTimestamp DESC

我收到错误提示语法错误。

  Exception Description: Syntax error parsing [SELECT m from (SELECT m from t1 m WHERE m.user = :user ORDER BY m.tTimestamp DESC) as h GROUP BY m.hNumber ORDER BY m.tTimestamp DESC]. 
   The right parenthesis is missing from the sub-expression.
   An identification variable must be provided for a range variable declaration.
   The query contains a malformed ending.

感谢任何帮助。

0 个答案:

没有答案