Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The method for assigning labels to various rows in the output of a query that uses the SUM function and has been grouped by is to use the keyword "AS" and specify the label name after the aggregated column in the SELECT statement. For example, if we have a query that sums the sales data for different products and groups them by category, we can label the aggregated column as "total_sales" like this:

SELECT category, SUM(sales) AS totalsales FROM salestable GROUP BY category

This will output the total sales for each category with a label "total_sales" assigned to the aggregated column.