I think you should use Group by for your requirement, and can't use Alias in Where condition in your case. (I'm using SQL Server, not sure if you have different tools)
I made some changes like that
SELECT
SUM(b.amount) AS sum_transection,
a.amount AS total,
SUM(b.amount) - a.amount AS diff
FROM
dbo.tb1 a INNER JOIN dbo.tb2 b ON
a.grp = b.grp AND a.head = b.head
GROUP BY a.grp, a.amount
having SUM(b.amount) - a.amount >0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…