我正在尝试使用带内连接的hibernate查询语言在mySQL DB中查找日期列的最大值
@Query("select u, CAST(MAX(o.last_modified AS DATE)) from com.dw.model.user.User as u left join com.dw.domain.order.Order as o on u.username=o.techid group by o.techid")
List<User> findUsers();我收到这个错误:-
expecting CLOSE, found 'AS' near line 1, column 36 select u,CAST(MAX(o.last_modified as DATE)) from com.dw.model.user.User as u left join com.dw.domain.order.Order AS o on u.username=o.techid group by o.techid
有没有人能告诉我如何在Hibernate中写这段代码?
发布于 2015-11-28 01:45:06
查询有几个问题。
1)正在对表别名u执行select操作。因为您是按o.techid分组的,所以我假设您在select中需要它。如果需要u中的某些列,请在select中显式指定这些列并对这些列执行group by操作。
2) CAST(MAX(o.last_modified AS DATE))应该是CAST(MAX(o.last_modified) AS DATE)
select o.techid, CAST(MAX(o.last_modified) AS DATE)
from com.dw.model.user.User as u
left join com.dw.domain.order.Order as o on u.username=o.techid
group by o.techidhttps://stackoverflow.com/questions/33962459
复制相似问题