SELECT x,y,SUM(f)-SUM(g)
FROM a,b
WHERE a.x = b.x
GROUP BY SUM(f)-SUM(g)
HAVING SUM(f)-SUM(g)>1
尝试使用GROUP BY x时,它可以正常工作,但我怎样才能进行GROUP BY SUM(f)-SUM(g)??
答案 0 :(得分:4)
您不需要按聚合列进行分组。你需要的是
SELECT x,y,SUM(f)-SUM(g)
FROM a,b
WHERE a.x = b.x
GROUP BY x,y
HAVING SUM(f)-SUM(g)>1