我想知道如何将此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
答案 0 :(得分:2)
问题解决了:
SELECT count(p), sum(p.price), s
FROM Passage p
INNER JOIN p.station s
GROUP BY s.name;
答案 1 :(得分:2)
ON
中没有JPQL
(JPA 2.0),但您可以执行隐式连接并使用WHERE子句:
假设实体Passage
atriburo StationID
与实体id
的属性Station
属于同一类型的对象。
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并给出正确答案。