Are subqueries the only option to reuse variables?
问题 I'd like to use MySQL in this form: SELECT 1 AS one, one*2 AS two because it's shorter and sweeter than SELECT one*2 AS two FROM ( SELECT 1 AS one ) AS sub1 but the former doesn't seem to work because it expects one to be a column. Is there any easier way to accomplish this effect without subqueries? And no, SELECT 2 AS two is not an option. ;) 回答1: select @one := 1 as one, 2 * @one as two; user-defined variables 回答2: Considering this SQL code SELECT 1 AS one, one*2 AS two from the