Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Sum Function In Sql in SQL

Sum Function In Sql in SQL

The SUM function in SQL is an aggregate function used to calculate the total sum of numeric values in a column or expression over a set of rows.


? Syntax

SUM(expression)
  • expression: A numeric column or an expression that evaluates to a number.


? What it does

  • Adds up all the values in the specified column or expression.

  • Ignores NULL values.

  • Returns a single numeric result.


? Example Usage

Suppose you have a table Sales with a column Amount:

SELECT SUM(Amount) AS TotalSalesFROM Sales;

This returns the total sum of all sales amounts.


More Examples

  1. Sum with WHERE clause:

SELECT SUM(Amount) AS TotalSales2023FROM SalesWHERE YEAR(SaleDate) = 2023;
  1. Sum grouped by category:

SELECT Category, SUM(Amount) AS TotalCategorySalesFROM SalesGROUP BY Category;

Notes

  • SUM works only with numeric data types.

  • Can be combined with GROUP BY to get sums per group.

  • Returns NULL if there are no rows (no matching data).


If you'd like, I can show you how to use SUM in more complex queries or with specific SQL dialects!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql