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


我知道不可能像这样减去这两个值,但是我不知道这样做的方法。那么,那将是什么呢?
谢谢

最佳答案

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

07-24 09:20