我有这个sql:
select u.USER from USERS u
left join (
select sum(OCUPATION) as OCU, USER from OCUPATION
where CONVERT(DATETIME, DATE, 103) BETWEEN CONVERT(DATETIME, '08/04/2012', 103)
AND CONVERT(DATETIME, '10/04/2013', 103) group by USER
) as ocu on u.USER = ocu.USER
where u.USER_ROLE = 1
and u.USER in (select a.USER from GROUP_USE_CLIE a where ID_CLIENT = 65)
group by u.USER, u.PRIORITY, ocu.OCU
order by PRIORITY, ocu.OCU;
此查询的目的是获取一个列表或User_role = 1的用户,可以在client = 65上工作,然后按优先级顺序排序,最后按Sum(Ocupation)排序,这就是我使用左连接和子查询的原因。查询工作正常,买我无法将其翻译为Hibernate Criteria。
有人能帮助我吗?
谢谢!