No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Using Aliases with GROUP BY
You can use an alias for any field or aggregated field in a SELECT list in a query. Specify the alias directly after the associated field. For example, the following query contains two aliases: n for the Name field, and max for the MAX(Amount) aggregated field.
1swfobject.registerObject("clippy.codeblock-0", "9");SELECT Name n, MAX(Amount) max
2FROM Opportunity
3GROUP BY NameYou can use a field alias to identify the field when you are processing the query results in your code.
Any aggregated field in a SELECT list that does not have an alias automatically gets an implied alias with a format expri, where i denotes the order of the aggregated fields with no explicit aliases. The value of i starts at 0 and increments for every aggregated field with no explicit alias.
In the following example, MAX(Amount) has an implied alias of expr0, and MIN(Amount) has an implied alias of expr1.
1swfobject.registerObject("clippy.codeblock-1", "9");SELECT Name, MAX(Amount), MIN(Amount)
2FROM Opportunity
3GROUP BY NameIn the next query, MIN(Amount) has an explicit alias of min. MAX(Amount) has an implied alias of expr0, and SUM(Amount) has an implied alias of expr1.
1swfobject.registerObject("clippy.codeblock-2", "9");SELECT Name, MAX(Amount), MIN(Amount) min, SUM(Amount)
2FROM Opportunity
3GROUP BY Name