在HQL中减去子选择值

时间:2012-11-23 13:01:32

标签: mysql hibernate hql subquery

我正在使用Hibernate,我想从两个不同的子查询中获取两个值的减法,但我得到以下错误:

  

SQLGramarEception:无法执行查询

SELECT termQuery.term.id,
   (SELECT COALESCE(MIN(termResult2.position),101) FROM termQuery2.results termResult2 WHERE termResult2.url.hostname MEMBER subscription.account.domains) as **prevPosition**, 
   (SELECT COALESCE(MIN(termResult.position),101) FROM termQuery.results termResult WHERE termResult.url.hostname MEMBER subscription.account.domains) as **currentPosition**,
   prevPosition - currentPosition as change --<<<<<<
FROM TermSubscription subscription, TermQuery termQuery, TermQuery termQuery2
WHERE subscription.account.id=1197 
    AND termQuery.term=subscription.term 
    AND termQuery.provider.id=2
    AND termQuery.queryDate.yearWeek = '201242'
    AND termQuery2.term=termQuery.term
    AND termQuery2.provider.id=termQuery.provider.id
    AND termQuery2.queryDate.yearWeek = '201241'
ORDER BY subscription.term.id, termQuery.queryDate.yearWeek

我知道不可能将这两个值减去,但我不知道如何做到这一点。那么,会是什么样的? 感谢

1 个答案:

答案 0 :(得分:0)

仅选择其他3个值,并在迭代查询结果时,从Java中的currentPosition中减去prevPosition