我有下面的sql语句
select items.id, ((sum(today.view_cnt) - sum(yesterday.view_cnt)) as point
from items
left outer join stats yesterday
on items.id = yesterday.items_id
and yesterday.base_date>='2013-05-29' and yesterday.base_date < '2013-05-30'
left outer join stats today
on items.id = today.items_id
and today.base_date >='2013-05-29' and today.base_date < '2013-05-30'
group by items.id
having sum(yesterday.view_cnt) >150
order by point desc
我想将其更改为 HQL 语句。其中一些我不知道如何更改为 HQL。
Criteria criteria = getSession().createCriteria(Stats.class, "seriesStats");
Criteria itemCriteria = criteria.createCriteria("items", "items", RIGHT_OUTER_JOIN, Restrictions.eq("items.id", ???? )); ---->
// 我想进行如下的 sql 查询 // 昨天在 items.id = 昨天.items_id 上的左外连接统计
criteria.setProjection(Projections
.projectionList()
.add(Projections.???????) -->
((sum(today.view_cnt) - sum(yesterday.view_cnt)) as point
.add(Projections.groupProperty("items.id")));
否则,我应该使用“查询”而不是“标准”吗?我想知道如何将 sql 语句更改为 Criteria 或 Query?
请告诉我。谢谢。