是的,您可以重用变量。这是您的操作方式:
SELECt @total_sale := s.f1 + s.f2 as total_sale, s.f1 / @total_sale as f1_percentFROM sales s
在此处了解更多信息:http :
//dev.mysql.com/doc/refman/5.0/en/user-
variables.html
[注意:此行为是不确定的。根据MySQL文档:]
通常,永远不要为用户变量分配值,并且不要在同一条语句中读取该值。您可能会得到预期的结果,但这不能保证。



