如何在HQL中查询不同的日期

时间:2013-02-22 15:11:16

标签: hibernate date hql distinct

我有一个表,其postgres中的列创建时间为timestamp。在我的一个类中,我需要使用HQL检索所有不同的创建时间。我尝试了不同的查询,如:

select distinct cast(creation_time as date) from Product;

但它总是返回Product对象的列表!然后我尝试了这个:

select year(pr.creationTime),month(pr.creationTime), day(pr.creationTime) from Product as pr;

但是这个也没用,它会给出这个错误:

function year(timestamp without time zone) does not exist

在这方面有任何帮助吗?

1 个答案:

答案 0 :(得分:0)

可以使用

select distinct to_char(creation_time, 'mm/dd/yyyy') from Product;