MySql SUM ALIAS

I have a problem with mysql alias.

I have this query:

SELECT (`number_of_rooms`) AS total, id_room_type, 
     COUNT( fk_room_type ) AS reservation , 
     SUM(number_of_rooms - reservation) AS result
FROM room_type
    LEFT JOIN room_type_reservation 
         ON id_room_type = fk_room_type
WHERE  result > 10
GROUP BY id_room_type

My problem start from SUM, cannot recognize reservation and then i want to use the result for a where condition. Like (where result > 10)

Answer

Not 100% but to the best of my knowledge you cant use aliases in your declarations, and thats why you are getting the column issue. Try this:

 SELECT (`number_of_rooms`) AS total, id_room_type,
     COUNT( fk_room_type ) AS reservation , 
     SUM(number_of_rooms - COUNT( fk_room_type ) ) AS result
 FROM room_type
     LEFT JOIN room_type_reservation 
         ON id_room_type = fk_room_type
 GROUP BY id_room_type
 Having SUM(number_of_rooms - COUNT( fk_room_type ) ) > 10