我需要实现一个命名查询,它返回一个按参加活动的朋友数量排序的活动列表。
例如,此查询返回按参加活动的人数排序的活动列表:
SELECT r.event
FROM RSVP AS r
JOIN r.event.rsvpList rr
WHERE r.profile.user.uuid = :userUuid
AND r.rsvpStatus = RSVPStatus.ATTENDING
GROUP BY r.event
ORDER BY COUNT(rr) DESC
或其他示例,朋友事件列表:
SELECT r.event
FROM RSVP AS r
WHERE r.profile IN
( SELECT f.profileTo
FROM Friend f
WHERE f.profileFrom.user.uuid = :userUuid
)
AND r.rsvpStatus = :rsvpStatus
GROUP BY r.event
我尝试执行以下操作:
SELECT r.event
FROM RSVP AS r
JOIN r.event.rsvpList rr
WHERE r.profile.user.uuid = :userUuid
AND r.rsvpStatus = RSVPStatus.ATTENDING
AND rr.profile IN
(
SELECT f.profileTo
FROM Friend f
WHERE f.profileFrom.user.uuid = :userUuid
)
GROUP BY r.event
ORDER BY COUNT(rr) DESC
但是这个查询返回了发生在朋友身上的事件并跳过了其他事件。
这是我的数据库的简化图: