I was wondering if MySQL has some kind of default alias for the current table you are building (like ‘self’ in SmallTalk or ‘this’ in Java). For instance:
SELECT
SUM(revenue) AS revenue,
SUM(units) AS units,
SUM(revenue)/SUM(units) AS revPerUnit,
-- I want to replace the above line with the below line:
self.revenue/self.units AS revPerUnit2
FROM inputTable;
I know that I could just use unabiguous aliases, but I want to know if there is a way to specify that you want the current table’s alias when there exists an ambiguous definition.
Usually, this is what I do on these cases:
Sometimes you have complicated queries and re-declaring the fields is not good for readability neither is for performance. Sub queries is the way to go.