Sample Header Ad - 728x90

New field based on sum field

0 votes
4 answers
6917 views
I'm trying to create a new field based in another (sum field) SELECT sum(price) AS old_price, old_price+100 AS total_price FROM sales This returns **Unknown column 'old_price' in 'field list'** sum is just a example, my real issue is to use with a select inside this field What am I doing wrong? Thanks. --edit I've used variables to reuse the alias, updated code: SELECT @old_price := sum(price) AS old_price, @old_price+100 AS total_price FROM sales If you think that it is not a good practice, tell me.
Asked by Juliano Lima (115 rep)
Mar 5, 2014, 07:02 PM
Last activity: Oct 20, 2023, 03:18 PM