Tutorials

SQL Aggregate Function


SQL SUM


In sql, SUM() function returns the total value of the columns having numeric value.

Syntax for SUM()

SELECT SUM(column_name)
FROM table_name
WHERE condition;

Example on SUM()

We will use 'tih_Courses' table for demonstration purpose

tih_Courses
Course_ID Course_Name Professor Mode_of_Training Course_Fee
001 .Net Mukesh Tiwari Online and Offline 550
002 Java Rajneesh Shukla Online and Offline 550
003 ANSI SQL Rajneesh Shukla Online 500
004 Basics of Computer Shweta  Online 350
005 Blogging Tutorial Puja  Online 250
006 JSP Alok Pandey Online and Offline 350
007 Servlet Mukesh Tiwari Online and Offline 350
Query-1: Write a sql query to calculate total course fee of all the courses
SELECT SUM(Course_Fee)
FROM tih_Courses

After above sql query gets executed, we will get following result:

SUM(Course_Fee)
2900

Query-2: Write a sql query to calculate the average course fee of Professor Mukesh Tiwari

SELECT SUM(Course_Fee)
FROM tih_Courses
WHERE Professor = 'Mukesh Tiwari';

After above sql query gets executed, we will get following result:

SUM(Course_Fee)
900

Similarly we can use SUM() on different column having numeric value applying different condition to get the total result.



Please Share this page
Views : 46
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!