SQL SUM() 関数

❮ 前章へ 次章へ ❯

SUM() Function

SUM() function returns the total sum of a numeric column.

SQL SUM() 構文

SELECT SUM(column_name) FROM table_name;

デモ・データベース

このチュートリアルでは、よく知られた Northwind サンプルデータベースを使用します。

Below is a selection from the "OrderDetails" table:

OrderDetailID OrderID ProductID Quantity
1 10248 11 12
2 10248 42 10
3 10248 72 5
4 10249 14 9
5 10249 51 40

SQL SUM() の例

following SQL statement finds the sum of all the "Quantity" fields for the "OrderDetails" table:

SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;

Try it Yourself ❯

❮ 前章へ 次章へ ❯