任何人都可以帮助为下面完美运行的 SQL 查询编写 HQL 查询吗
select d2.user_id,d2.push_token,d2.registration_date from device_registration d2,(
select max(d1.registration_date) as registration_date,d1.push_token from device_registration d1
where d1.push_Token != 'null' and d1.push_Token is not null and d1.push_Token!=''
group by d1.push_token) d3
where d2.push_token=d3.push_token and d2.registration_date=d3.registration_date
order by d2.registration_date asc
最佳答案
这是查询,稍微重新格式化:
select d2.user_id, d2.push_token, d2.registration_date
from device_registration d2 join
(select max(d1.registration_date) as registration_date, d1.push_token
from device_registration d1
where d1.push_Token <> 'null' and d1.push_Token is not null and d1.push_Token <> ''
group by d1.push_token
) d3
on d2.push_token = d3.push_token and d2.registration_date = d3.registration_date
order by d2.registration_date asc;
它本质上是获取每个push_token
的最长注册日期。以下内容应遵循 HQL 标准:
select 2.*
from device_registration d
where not exists (select 1
from device_registration d2
where d2.push_token = d.push_token and d2.registration_date > d.registration_date
)
order by d.registration_date desc;
关于java - HQL 可完美运行嵌套 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25284234/