jpa 将SQL语句转换为JPQL语句

e5njpo68  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(94)

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

sdnqo3pr

sdnqo3pr1#

JPQL(JPA 2.0)中没有ON,但您可以执行隐式连接并使用WHERE子句:
假设实体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

建议如果问题可以添加实体站通道并给给予一个正确答案。

r8xiu3jd

r8xiu3jd2#

问题已解决:

SELECT count(p), sum(p.price), s 
FROM Passage p 
INNER JOIN p.station s 
GROUP BY s.name;

相关问题