Aggregate Functions in MySQL
SUM, COUNT, MIN, MAX, AVG AND STRING FUNCTIONS - UCASE, FORMAT
CONCAT,CHAR_LENGTH and LEFT FUNCTIONS
SELECT
count(*) from employee; -- Here we use COUNT how many employee
If we need
count of Manager
SELECT count(*)
Manager
FROM employee
WHERE job_Desc ="Manager";
-- Average
function
SELECT avg(salary)
FROM employee
WHERE Job_Desc ="manager";
-- SUM
function
select
sum(salary)
from
employee
where
Job_Desc="Analyst";
-- MAX and
MIN function
select MAX(SALARY)
from
employee;
select
MIN(SALARY)
from
employee;
-- STRING
-- UCASE
function for UPPER CASE
select ucase(ename) Name,salary --- Here we used Alias name
from
employee;
-- We can
count the character in Name column for that Char_Length function
select
ename,char_length(ename) No_Character
from
employee;
-- Here we
use CONCAT function ,CONCAT mean join
/* Here
before the salary i want RS so using CONCAT function */
select
ename,concat('Rs.',salary) Salary
from
employee;
-- FORMAT function
/* Here
FORMAT function used to separate the digit and that 0 for decimal values */
select
ename,concat('Rs.',format(salary,0)) Salary
from
employee;
-- LEFT
function
/* Here i
need Job desc first three letter so used LEFT */
select ename,LEFT(Job_desc,3)
from
employee;
Comments