SQL COUNT(), AVG() and SUM() Functions

The SQL COUNT (), AVG () and SUM () functions are aggregate functions, which are used to perform calculation on multiple rows and return a single value.All aggregate functions by default exclude nulls values before working on the data.

COUNT Function:
COUNT Function is used to return total number of rows that matches a specified criteria.COUNT(*) also considers Nulls and duplicates.

COUNT Function Syntax :

The syntax of the COUNT Function is −

SELECT COUNT(column-name)
FROM table-name
WHERE condition;



AVG() Functions :

AVG Function is used to return average value of rows that matches a specified criteria.AVG() function works only on numeric data types.



AVG() Functions Syntax :

The syntax of the AVG() Functions is −

SELECT AVG(column-name)
FROM table-name
WHERE condition;



SUM() Functions :

SUM Function is used to return total sum of rows that matches a specified criteria. SUM only works on numeric fields. Null values ​​are excluded from the returned result.



SUM() Functions Syntax :

The syntax of the SUM() Functions is −

SELECT SUM(column-name)
FROM table-name
WHERE condition;



SQL COUNT(), AVG() and SUM() Example :

Consider the Customer table with the following records -

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
2 Vivaan 25 Mumbai 30000
3 Reyansh 28 Chennai 35000
4 Muhammad 24 Udaipur 50000
5 Sai 30 Mumbai 27000


COUNT Example:- The following code is an example that will return the total customer IDs in the table.

SELECT COUNT(CustomerID)
FROM Customer;


The result for the respective sql query is as follows −

COUNT(CustomerID)
5



AVG Example:-The following code is an example that will return the average of CustomerSalary in the table.

SELECT AVG(CustomerSalary)
FROM Customer;


The result for the respective sql query is as follows −

AVG(CustomerSalary)
34000



SUM Example:- The following code is an example that will return the SUM of CustomerSalary in the table.

SELECT SUM(CustomerSalary)
FROM Customer;


The result for the respective sql query is as follows −

SUM(CustomerSalary)
170000



Visit :


Discussion



* You must be logged in to add comment.

pHqghUme
555

pHqghUme
555

pHqghUme
555

pHqghUme
-1 OR 2+810-810-1=0+0+0+1 --

pHqghUme
-1 OR 3+810-810-1=0+0+0+1 --

pHqghUme
-1 OR 3*2<(0+5+810-810) --

pHqghUme
-1 OR 3*2>(0+5+810-810) --

pHqghUme
-1 OR 2+915-915-1=0+0+0+1

pHqghUme
-1 OR 3+915-915-1=0+0+0+1

pHqghUme
-1 OR 3*2<(0+5+915-915)

pHqghUme
-1 OR 3*2>(0+5+915-915)

pHqghUme
-1' OR 2+206-206-1=0+0+0+1 --

pHqghUme
-1' OR 3+206-206-1=0+0+0+1 --

pHqghUme
-1' OR 3*2<(0+5+206-206) --

pHqghUme
-1' OR 3*2>(0+5+206-206) --

pHqghUme
-1' OR 2+689-689-1=0+0+0+1 or 'JYZj548z'='

pHqghUme
-1' OR 3+689-689-1=0+0+0+1 or 'JYZj548z'='

pHqghUme
-1' OR 3*2<(0+5+689-689) or 'JYZj548z'='

pHqghUme
-1' OR 3*2>(0+5+689-689) or 'JYZj548z'='

pHqghUme
-1" OR 2+599-599-1=0+0+0+1 --

pHqghUme
-1" OR 3+599-599-1=0+0+0+1 --

pHqghUme
-1" OR 3*2<(0+5+599-599) --

pHqghUme
-1" OR 3*2>(0+5+599-599) --

pHqghUme
if(now()=sysdate(),sleep(15),0)

pHqghUme
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

pHqghUme
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

pHqghUme
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

pHqghUme
-1; waitfor delay '0:0:15' --

pHqghUme
-1); waitfor delay '0:0:15' --

pHqghUme
1 waitfor delay '0:0:15' --

pHqghUme
XDLXGi8X'; waitfor delay '0:0:15' --

pHqghUme
-5 OR 730=(SELECT 730 FROM PG_SLEEP(15))--

pHqghUme
-5) OR 512=(SELECT 512 FROM PG_SLEEP(15))--

pHqghUme
-1)) OR 205=(SELECT 205 FROM PG_SLEEP(15))--

pHqghUme
eq7MNU5N' OR 476=(SELECT 476 FROM PG_SLEEP(15))--

pHqghUme
lhtYi9De') OR 319=(SELECT 319 FROM PG_SLEEP(15))--

pHqghUme
cRRSvySX')) OR 61=(SELECT 61 FROM PG_SLEEP(15))--

pHqghUme
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

pHqghUme
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

pHqghUme
1'"

pHqghUme

pHqghUme
@@6T4OH

pHqghUme
555

pHqghUme
555

pHqghUme
555