1
に参加:書き換え自己は、私は、この自己JPQLに参加変換する必要がありJPQL
SELECT s1.*
FROM site AS s1
JOIN (SELECT site_type, MAX(last_update_date) AS LastUpdate
FROM site
WHERE site.last_update_date > "2011-02-27 16:57:53"
GROUP BY site_type) AS s2
ON s1.site_type = s2.site_type
AND s1.last_update_date = s2.LastUpdate
ORDER BY s1.last_update_date DESC
編集:ソリューション:
SELECT s1
FROM Site s1
WHERE s1.lastUpdateDate = (SELECT MAX(s2.lastUpdateDate)
FROM Site s2
WHERE s1.siteType = s2.siteType)
AND s1.lastUpdateDate > "2011-02-27 16:57:53"
ORDER BY s1.lastUpdateDate DESC
代わりの自己結合、私は余分な選択を使用しましたlastUpdateDateのステートメント
編集2:これは、NULL値も含むため、これはより良い解決策です。唯一の欠点は、TypedQueryを使用できないことです。
SELECT s.id, s.url, s.siteType, MAX(s.lastUpdateDate) as maxLastUpdateDate
FROM Site s
GROUP BY s.siteType
HAVING (maxLastUpdateDate < "2011-02-27 16:57:53" OR maxLastUpdateDate IS NULL)