1

我想知道如何将此 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

会不会是这样的:

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

?

4

2 回答 2

3

(JPA 2.0)中没有ONJPQL但您可以进行隐式连接并使用 WHERE 子句:

假设实体Passageatriburo 与实体的属性是StationID同一类型的对象。idStation

SELECT SUM(s.price) Income, COUNT(p) Passages, s.Name
FROM Passage p, Station s
WHERE p.stationId = s.id
GROUP BY s.Name

建议如果问题可以添加实体Station Passage并给出正确答案。

于 2013-05-15T20:27:34.763 回答
2

问题解决了:

SELECT count(p), sum(p.price), s 
FROM Passage p 
INNER JOIN p.station s 
GROUP BY s.name;
于 2013-05-15T19:36:57.233 回答