Hibernate 查询语言中的 Postgres DISTINCT ON 等价物

Postgres DISTINCT ON eqivalent in Hibernate Query Language

我需要 Postgres DISTINCT ON 等同于 HQL。例如考虑以下内容。

SELECT DISTINCT ON (Col2) Col1, Col4 FROM tablename;

在 table

Col1 | Col2 | Col3 | Col4
---------------------------------
AA1  | A    |  2    | 1
AA2  | A    |  4    | 2
BB1  | B    |  2    | 3
BB2  | B    |  5    | 4

Col2不会显示在结果中如下

Col1 | Col4
------------
AA1  |  1
BB1  |  3

谁能用HQL给出一个解决方案。我需要使用 DISTINCT,因为它是更大查询的一部分。

抱歉,我误解了你的问题:

不,Hibernate 不支持 DISTINCT ON 查询。

您的问题可能与此重复:Postgresql 'select distinct on' in hibernate