Fungsi SUM() SQL
- Halaman Sebelumnya SQL min()
- Halaman Berikutnya SQL Group By
Fungsi SUM()
Fungsi SUM() mengembalikan jumlah total kolom numerik (total).
Syarat SUM() SQL
SELECT SUM(column_name) FROM table_name
Contoh SUM() SQL
Kami memiliki tabel "Orders" seperti berikut:
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 untuk kolom "OrderPrice".
Kami menggunakan kalimat SQL seperti berikut:
SELECT SUM(OrderPrice) AS OrderTotal FROM Orders
Hasil seperti ini:
OrderTotal |
---|
5700 |
- Halaman Sebelumnya SQL min()
- Halaman Berikutnya SQL Group By