SUM Function is SQL:
SUM is an aggregate function that evaluates the sum of the expression over a set of rows (see Aggregates). SUM is allowed only on expressions that evaluate to numeric data types.
Syntax
SUM ( [ DISTINCT | ALL ] Expression )The DISTINCT and ALL qualifiers eliminate or retain duplicates. ALL is assumed if neither ALL nor DISTINCT is specified. For example, if a column contains the values 1, 1, 1, 1, and 2, SUM(col) returns a greater value than SUM(DISTINCT col).
Only one DISTINCT aggregate expression per SelectExpression is allowed. For example, the following query is not allowed:
select AVG(DISTINCT flying_time), SUM(DISTINCT miles)
FROM flights;
The resulting data type is the same as the expression on which it operates (it might overflow).
Examples
– find all economy seats available:select SUM(economy_seats)
FROM airlines;
– use SUM on multiple column references
– (find the total number of all seats purchased):
– (find the total number of all seats purchased):
select SUM(economy_seats + business_seats_taken + firstclass_seats_taken) as seat_taken
FROM flightavailability;
No comments:
Post a Comment
comments are welcome