Конвертировать SQL-запрос в querydsl - PullRequest
0 голосов
/ 07 октября 2019

У меня есть эта таблица профиль :

enter image description here

Я хочу извлечь строки для профилей, которые имеют form=finalи являются самыми последними (year=max) для отдельных стран, то есть результаты запросов будут:

enter image description here и т. д.

Есть ли способпреобразовать один из следующих запросов в формат JPAQuery или querydsl? (первый относится к Postgres)

Select distinct on (p.country) * from profile p where p.form='final' order by p.country, p.year desc;

или

SELECT p.id, p.country, p.version, p.year from profile p inner join (SELECT DISTINCT country as c, max(year) as y from profile where form='final' group by country) as pro on pro.c=p.country and pro.y=p.year where form='final';

...