0

是否可以创建生成以下 sql 的条件:

select name from (select distinct name from person) as aliasname  order by lower(name);

这里有两个 sql -

  1. select distinct name from person

  2. select name from <output of 1> as aliasname order by lower(name)

我想创建标准然后做criteria.list()

4

2 回答 2

1

我认为,这将满足您的需求:

criteria.addOrder(Order.asc("name").ignoreCase())
        .setProjection(Projections.distinct(Projections.property("name")))
        .list();

或者,此条件使用带有名称投影的 DetachedCriteria 作为子查询:

DetachedCriteria distinctNamesCriteria = DetachedCriteria.forClass(Person.class);
distinctNamesCriteria.setProjection(Projections.distinct(Projections.property("name")));

criteria.add(SubQueries.propertyIn("name", distinctNamesCriteria))
        .addOrder(Order.asc("name").ignoreCase())
        .list();
于 2013-06-26T12:55:21.037 回答
-1

我没有给你的答案,但你为什么要进行第二次选择?

SELECT DISTINCT NAME FROM PERSON AS ALIASNAME ORDER BY LOWER(NAME)

将返回相同的数据。

于 2013-06-26T12:55:12.193 回答