Fungsi SUM() SQL

Fungsi SUM()

Fungsi SUM() mengembalikan total dari kolom numerik (jumlah keseluruhan).

Syarat SUM() SQL

SELECT SUM(column_name) FROM table_name

Contoh SUM() SQL

Kami memiliki tabel "Orders" seperti ini:

O_Id OrderDate OrderPrice Customer
1 2008/12/29 1000 Bush
2 2008/11/23 1600 Carter
3 2008/10/05 700 Bush
4 2008/09/28 300 Bush
5 2008/08/06 2000 Adams
6 2008/07/21 100 Carter

Sekarang, kami ingin mencari jumlah total "OrderPrice" bidang.

Kami menggunakan kalimat SQL seperti ini:

SELECT SUM(OrderPrice) AS OrderTotal FROM Orders

Hasil set seperti ini:

OrderTotal
5700