-- How to use alias as field in mysql -- http://stackoverflow.com/questions/6081436/how-to-use-alias-as-field-in-mysql select @code:= SUM(field1 + field2), @code+1 from abc;