SQL Tutorial

SQL SELECT SUM: Understanding the SUM() Function in SQL

SQL SELECT SUM
SQL SELECT SUM

SQL SELECT SUM: Understanding the SUM() Function

The SQL SUM() function is a powerful aggregate function that returns the total of a numeric column. It is widely used in data analysis and reporting to calculate totals across multiple records.

Complete Python Course with Advance topics:-
SQL Tutorial:-

SQL SUM() Syntax

SELECT SUM(expression)
FROM table_name
WHERE conditions;

Example 1: SUM with a Single Column

SELECT SUM(salary) AS "Total Salary"
FROM employees
WHERE salary > 25000;
-- Result: 112000

Example 2: SUM with DISTINCT

SELECT SUM(DISTINCT salary) AS "Total Salary"
FROM employees
WHERE salary > 25000;

This ensures duplicate salary values are not counted more than once.

Example 3: SUM with GROUP BY

SELECT department, SUM(daily_sales) AS "Total Sales"
FROM sales_data
GROUP BY department;
DEPARTMENTTOTAL SALES
IT1100
HR500
FINANCE400

Example 4: SUM with GROUP BY and HAVING

Use HAVING to filter grouped results ÔÇö for example, only departments with total sales above 500:

SELECT department, SUM(daily_sales) AS total
FROM sales_data
GROUP BY department
HAVING SUM(daily_sales) > 500;

Download New Real Time Projects:- Click here
Complete Advance AI topics:-

Conclusion

The SUM() function is crucial for aggregate calculations. Whether summing single columns, distinct values, or grouped reports with HAVING, it simplifies data analysis. For more SQL insights, stay connected with .

sql sum multiple columns
sql sum group by
sql sum with condition
sql sum having clause
sql average group by
sql sum distinct
sql select sum example
sql select sum w3schools

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us