Tema: cómo sumar
Ver Mensaje Individual
  #2  
Antiguo 27-06-2003
Avatar de Investment
Investment Investment is offline
Miembro
 
Registrado: may 2003
Posts: 378
Reputación: 24
Investment Va por buen camino
Sacado del Local SQL Help:


Calculates the sum of values for a column.

SUM([ALL] column_reference | DISTINCT column_reference)

Description

Use SUM to sum all the values in the specified column. As an aggregate function, SUM performs its calculation aggregating values in the same column(s) across all rows in a dataset. The dataset may be the entire table, a filtered dataset, or a logical group produced by a GROUP BY clause. Column values of zero are included in the aggregation. NULL column values are not counted in the calculation. If the number of qualifying rows is zero, SUM returns a NULL value.

SELECT SUM(itemstotal)

FROM orders

ALL returns the smallest value for all rows. When DISTINCT is not specified, ALL is the implied default.

DISTINCT ignores duplicate values when calculating the smallest value in the specified column.

MIN returns the smallest value in a column or a calculation using a column performed for each row (a calculated field).

SELECT SUM(itemstotal), SUM(itemstotal * 0.0825) AS TotalTax

FROM orders

When used with a GROUP BY clause, SUM returns one calculation value for each group. This value is the aggregation of the specified column for all rows in each group. The statement below aggregates the total value for the order totals column in the ORDERS table, producing a subtotal for each company in the COMPANY table.

SELECT C."company", SUM(O."itemstotal") AS SubTotal

FROM "customer.db" C, "orders.db" O
WHERE (C."custno" = O."custno")
GROUP BY C."company"

ORDER BY C."company"

Applicability

SUM operates only on numeric values. To use SUM on non-numeric values, first use the CAST function to convert the column to a numeric type.
__________________
Saludos,
Peter Investment
Responder Con Cita