想要获取记录但指望使用 HQL 区分具有重复值的列
Want to fetch records but counting on distinction of column with duplicate values using HQL
我将 BusinessParty POJO 对象映射到 table BP table,
请求映射到 REQUESTS table.
的 POJO 对象
一个 BP 在 REQUESTS table by Foreign Key 中有多个请求。
我只想通过提供 DAO 所需的 BP 计数来获取请求,并从 REQUEST table.
获取该计数的所有请求(比如 10)BP 请求
我最初在 Oracle 中尝试 SQL
select * from REQUESTS where BP_ID in (select distinct BP_ID from REQUESTS where ROWNUM<=200);
但是在这个内部查询中搜索了 200 行,它找到了 95 个 BPs 和外部查询 return 我有 217 条 REQUESTS 记录,其中 95 个 BPs。
我必须再次将生成的查询转换为 HQL。
不知道如何获取特定数量的 BP 的所有请求。
我不确定,如果我理解,你想做什么,但我认为问题是,Oracle 限制了 rownum 而不是区分。如果你想获得 200 unique BP_IDs,你必须再做一个子查询:
select *
from REQUESTS
where BP_ID in (select BP_ID from (Select distinct BP_ID from REQUESTS) where ROWNUM<=200);
我将 BusinessParty POJO 对象映射到 table BP table, 请求映射到 REQUESTS table.
的 POJO 对象一个 BP 在 REQUESTS table by Foreign Key 中有多个请求。
我只想通过提供 DAO 所需的 BP 计数来获取请求,并从 REQUEST table.
获取该计数的所有请求(比如 10)BP 请求我最初在 Oracle 中尝试 SQL
select * from REQUESTS where BP_ID in (select distinct BP_ID from REQUESTS where ROWNUM<=200);
但是在这个内部查询中搜索了 200 行,它找到了 95 个 BPs 和外部查询 return 我有 217 条 REQUESTS 记录,其中 95 个 BPs。
我必须再次将生成的查询转换为 HQL。
不知道如何获取特定数量的 BP 的所有请求。
我不确定,如果我理解,你想做什么,但我认为问题是,Oracle 限制了 rownum 而不是区分。如果你想获得 200 unique BP_IDs,你必须再做一个子查询:
select *
from REQUESTS
where BP_ID in (select BP_ID from (Select distinct BP_ID from REQUESTS) where ROWNUM<=200);