Aggregate Functions Count, Sum, Min, Max, Avg tutorial in php

 SELECT with Aggregate Functions Syntax :

SELECT COUNT(column_name) FROM table_name WHERE condition;

SELECT SUM(column_name) FROM table_name WHERE condition;


If we want to COUNT total number of records from table using COUNT from table name "personal" then we can use below sql command :

SELECT COUNT(*) FROM personal;


If we want to COUNT total number of DISTINCT cities records from table using COUNT from table name "personal" by Renaming column name as "Count" then we can use below sql command :

SELECT COUNT(DISTINCT city) AS Count FROM personal;


If we want to select Maximum Age from records using "Max" from table name "personal" by Renaming column name as "Maximum Age" then we can use below sql command :

SELECT MAX(age) AS MaximumAge, name, city, id, phone FROM personal;


If we want to select Minumum Age from records using "Min" from table name "personal" by Renaming column name as "MinimumAge" then we can use below sql command :

SELECT MIN(age) AS MinimumAge, name, city, id, phone FROM personal;


If we want to count SUM of any columns records using SUM from table name "personal" by Renaming column name as "Sumof" then we can use below sql command :

SELECT SUM(percentage) AS Sumof FROM personal;


If we want to count Average of any columns records using AVG from table name "personal" by Renaming column name as "Average" then we can use below sql command :

SELECT AVG(percentage) AS Average FROM personal;

Comments

Popular posts from this blog

Logical_Operators

SubQuery with EXISTS and NOT EXISTS in PHP

Get Functions