I'm attempting to use MySQL's user defined variables, but due to restrictions I can't use them in the same way as it demonstrates, where one query sets the variable and a second uses it. My requirement is to be able to use it multiple times in a query.
Consider the following:
SELECT (Some Really Taxing Calculation) AS Total FROM Purchases
WHERE Total < 55 AND itemName = "Bananas"
OR Total > 90 AND itemName = "Apples"
OR Total = 30 AND itemName = "Peaches"
ORDER BY Total
It'd be really nice to only run the Total calculation once, and then use the result multiple times throughout the query. Right now, the only way I've gotten it to work in one query is to rerun it for every place it's used as Total returns an error saying an unknown column has been used.
total.Value.