[英]JPA Named query
Hey I'm new to JPA and fairly new to SQL and I need to write a slection query 嘿,我是JPA的新手,对SQL很新,我需要编写一个选择查询
I need to : 我需要 :
"Select all payments where the amount is more than the average value of all USD payments" “选择金额超过所有美元付款平均价值的所有付款”
I have a JPA entity : 我有一个JPA实体:
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private Long id;
private String account;
private double amount;
private String currency;
I tried with : 我尝试过:
@NamedQuery(name="payByUSD" , query="SELECT x FROM Payment x WHERE x.amount > (SELECT AVG(x.amount)from Payment)")
but I got the following error: 但我收到以下错误:
- The FROM clause must defined at least one identification variable declaration.
- The right expression is missing from the arithmetic expression.
Can anyone point me in the right direction. 任何人都可以指出我正确的方向。
Use 使用
SELECT x FROM Payment x
WHERE x.amount > (SELECT AVG(p.amount) from Payment p)
Your subquery is 你的子查询是
SELECT AVG(x.amount) from Payment
, and x
is not defined. ,
x
未定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.