是否可以创建生成以下 sql 的条件:
select name from (select distinct name from person) as aliasname order by lower(name);
这里有两个 sql -
select distinct name from person
select name from <output of 1> as aliasname order by lower(name)
我想创建标准然后做criteria.list()
是否可以创建生成以下 sql 的条件:
select name from (select distinct name from person) as aliasname order by lower(name);
这里有两个 sql -
select distinct name from person
select name from <output of 1> as aliasname order by lower(name)
我想创建标准然后做criteria.list()
我认为,这将满足您的需求:
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();
我没有给你的答案,但你为什么要进行第二次选择?
SELECT DISTINCT NAME FROM PERSON AS ALIASNAME ORDER BY LOWER(NAME)
将返回相同的数据。