SQL COUNT Function:
We are going to write an SQL query to count the number of rows in a table. For is we will be making use of the count() function of SQL.
The SQL COUNT( ) function is used to return the number of rows in a table. It is used with the Select( ) statement.
If we have employee table with the following column emp_id, emp_name, emp_email, emp_contact_number and we have to count the number of rows in a table then we will do like this.
table_name : emmployee
column_name : salary
SYNTAX:
SELECT COUNT(column_name) from table_name;
QUERY :
SELECT COUNT(salary) from employee
Note : We can use any of the column_name to count the number of rows in the table.
SQL AVG Function:
We are going to see how to find the average value in a column in SQL. A column in the SQL table is the vertical catalog structure.
Average of all values in a column
For this, we need to use avg() function. We have to pass the column name as a parameter. The avg() function has the following syntax:
SYNTAX:
SELECT AVG( column_name ) FROM table_name;
QUERY:
SELECT AVG( salary ) FROM employee;
SQL SUM Function:
SELECT SUM is used to calculate the total value of an expression in SQL. It is the same as using the AGGREGATE function SUM ( ) in SQL.
In this article, we are going to see how to use “SELECT SUM” in SQL using suitable examples.
SYNTAX:
SELECT SUM(column_name) FROM table_name WHERE condition;
QUERY:
SELECT SUM(salary) FROM employee WHERE salary > 50000;
0 Comments