4

嘿,我是 JPA 的新手,对 SQL 还很陌生,我需要编写一个选择查询

我需要 :

“选择金额超过所有美元付款平均值的所有付款”

我有一个 JPA 实体:

@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
private String account;
private double amount;
private String currency;

我试过:

@NamedQuery(name="payByUSD" , query="SELECT x FROM Payment x WHERE x.amount > (SELECT AVG(x.amount)from Payment)")

但我收到以下错误:

- The FROM clause must defined at least one identification variable declaration.
- The right expression is missing from the arithmetic expression.

谁能指出我正确的方向。

4

1 回答 1

5

利用

SELECT x FROM Payment x 
WHERE x.amount > (SELECT AVG(p.amount) from Payment p)

您的子查询是

SELECT AVG(x.amount) from Payment

, 并且x没有定义。

于 2012-12-16T13:11:03.340 回答