在Mysql for JPA中替代ABS()

时间:2014-03-06 10:45:24

标签: java mysql sql jpa jpql

我的表格如下: -

+----+-------+
| ID | Score |
+----+-------+
| 3  | -10   |
| 2  | -11   |
| 4  | -9    |
| 5  | 1     |
| 1  | 12    |
+----+-------+

,我期待输出

+----+-------+
| ID | Score |
+----+-------+
| 1  | 12    |
| 2  | -11   |
| 3  | -10   |
| 4  | -9    |
| 5  | 1     |
+----+-------+

虽然我有查询

SELECT * 
  FROM Table 
ORDER BY 
       ABS(score) DESC;


我希望用JPQL / JPA替换它。

1 个答案:

答案 0 :(得分:1)

Query query=em.createQuery("SELECT p FROM Product p WHERE ABS(p.price)<50.0");

来自source