1

我正在使用 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

我知道不可能像这样减去这两个值,但我不知道该怎么做。那么,会有什么办法呢?谢谢

4

1 回答 1

0

仅选择其他 3 个值,并在迭代查询结果时,currentPositionprevPositionJava 中的 ,​​ 中减去 。

于 2012-11-23T13:10:14.243 回答