Relational totals use case

This example shows how to use relational totals to return a grand total row as the last row of the result set.
Note how totals are only computed for the height measure with an additive statistic SUM, and not weight which uses AVG.

		DataSelection query = buildClassroomDataSelection();

		//get all the result items
		List resultItems = query.getResultItems();
		DataItem height = (DataItem) resultItems.get(3);
		DataItem weight = (DataItem) resultItems.get(4);

		//get the SUM and MAX functions as known by the server:
		ServerProperties serverProperties = query.getServerProperties();
		Function sumFunction = serverProperties.getFunctionByNameID(FunctionNameID.SUM);
		Function maxFunction = serverProperties.getFunctionByNameID(FunctionNameID.MAX);

		height.setAggregationType(sumFunction);
		weight.setAggregationType(maxFunction);

		//Make the query return a final, grand total row last, containing the total
		//over all values of a column:
		query.setTotalType(BusinessQuery.GRANDTOTAL, Role.COLUMN);

		//execute the query

The result is shown below: