This Query is giving me an error of #1054 – Unknown column ‘totalamount’ in ‘where clause’
SELECT (amount1 + amount2) as totalamount
FROM `Donation`
WHERE totalamount > 1000
I know i can resolve this error by using group by clause and replace my where condition with having clause. But is there any other solution beside using having clause. If group by is the only solution then I want to know why I have to use group by clause even I havent use any aggregate function
thanks.
I would not expect MySQL to give that error message, but many other databases do. In other databases you can work around it by repeating the column definition:
Or you can use a subquery to avoid the repitition:
Live example at SQL Fiddle.