2 qrq813029 qrq813029 于 2014.12.01 17:04 提问

jpql 通过子查询结果排序问题

jpql 怎么将子查询结果作为排序条件
比如 sql语句:select u.id,u.account,u.name,(select COUNT(m) from Usermessage m where m.userid=u.id and m.isreaded=0) AS aa from Memberuser u ORDER BY aa DESC
这样给他起个别名“aa”完全可以,但是这样在jpql里就不行,老是识别不了aa,jpql是通过实体类来查询的,所以我觉得order by后面必须格式为**.**才行,可这个子查询咋办

1个回答

devmiao
devmiao   Ds   Rxr 2014.12.01 23:30

Sub-selects in FROM clause

As of EclipseLink 2.4, sub-selects are supported in the FROM clause. This requires that the database supports this functionality.

SELECT e, c.city FROM Employee e, (SELECT DISTINCT a.city FROM Address a) c WHERE e.address.city = c.city

http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Support_for_Native_Database_Functions#Sub-selects_in_FROM_clause

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!