[英]Convert SQL statement to JPQL statement
I wonder how I convert this SQL statement to JPQL: 我想知道如何将此SQL语句转换为JPQL:
SELECT sum(price) AS Income, count(*) AS Passages, Station.Name
FROM Passage
INNER JOIN station ON passage.stationId = station.id
GROUP BY Station.Name
wouldnt it be something like this: 不会是这样的:
SELECT sum(price) AS Income, count(p) AS Passages, s.Name FROM Passage p
INNER JOIN station s
ON p.stationId = s.id GROUP BY s.Name
? ?
Problem solved with: 问题解决了:
SELECT count(p), sum(p.price), s
FROM Passage p
INNER JOIN p.station s
GROUP BY s.name;
There is no ON
in JPQL
(JPA 2.0), but you can do an implicit join and use the WHERE clause: JPQL
(JPA 2.0)中没有ON
,但您可以执行隐式连接并使用WHERE子句:
Assuming that the entity Passage
the atriburo StationID
is the same type of object that the attribute id
of the entity Station
. 假设实体
Passage
atriburo StationID
是与实体Station
的属性id
相同的对象类型。
SELECT SUM(s.price) Income, COUNT(p) Passages, s.Name
FROM Passage p, Station s
WHERE p.stationId = s.id
GROUP BY s.Name
It is recommended that if the question can add entities Station Passage and to give a correct answer. 建议如果问题可以添加实体Station Passage并给出正确的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.