Manual No 7
Manual No 7
Objectives
Familirization with SQL Functions
SQL Functions
These functions are used to manipulating data items and returning the results.
• Sum()
• Avg()
• Min()
• Max()
• Count()
Sum()
Sum() used to find out the sum of the salary of employees.
Ex:List the sum of the salary of employees
Select sum(sal) from emp;
Output
3 Lab 7: SQL
Min()
Min() used to find out the minimum salary of an employee in the given table.
Ex:list out the minimum salary of an employee in the emp table.
Select min(sal) from emp;
Output
Max()
Max() used to find out the maximum salary of an employee in the given table.
Ex:list out the maxiimum salary of an employee in the emp table.
Select max(sal) from emp;
Output
Count()
Count() used to list out the number of values in a particular table.
Ex:
1.List the numbers of jobs.
select count (job) from emp;
Output
Power()
Power():find the power.
Select power(2,3) from dual;
Output
Sqrt()
Sqrt() used to find the square root of a given value.
Select sqrt(9) from dual;
Output
Round()
Round() used to find the round of the value.
Select round(12.35,1) from dual;
Output
Truncate()
Truncate() used to find the truncate value.
Select trunc(12.35,1) from dual;
3 Lab 7: SQL
Exp()
Exp() used to used to find the exponential of given number.
Select exp(3) from dual;
Greatest()
Greastest() used to find out the greater value.
Select greatest(10,20,30) from dual;
Output
Least()
Least() used to find out the leastervalue.
Select least(10,20,30) from dual;
Mod()
Mod() used to fina tha module of given numbers.
Select mod(3,2) from dual;
Floor()
Floor() used to find the floor value.
Select floor(12.56) from dual;
Sign()
Sign() used to find the sign of a number.
3
Log()
Log() used to find logarithmic value.
Select log(3,2) from dual;
In these function we are using date functions also there are listed below:
SOLUTION:
create database [lab 8]
use [lab 8]
CREATE TABLE emp (
empno INT PRIMARY KEY,
ename VARCHAR(10),
job VARCHAR(9),
mgr INT,
hiredate DATE,
sal NUMERIC(7, 2),
comm NUMERIC(7, 2),
deptno INT
);
-- Inserting sample data
INSERT INTO emp VALUES
(7369, 'SMITH', 'CLERK', 7902, '17-DEC-1980', 800, NULL, 20),
(7499, 'ALLEN', 'SALESMAN', 7698, '20-FEB-1981', 1600, 300, 30),
(7521, 'WARD', 'SALESMAN', 7698, '22-FEB-1981', 1250, 500, 30),
(7839, 'KING', 'PRESIDENT', NULL, '17-NOV-1981', 5000, NULL, 10);
-- Verify the data
SELECT * FROM emp;
-- sum of salary
SELECT SUM(sal) AS SUM_ FROM emp;
-- Average od salary
SELECT AVG(sal) AS AVG_ FROM emp;
-- Minimum Salary
SELECT MIN(sal) AS MIN_ FROM emp;
-- Maximum Salary
SELECT MAX(sal) AS MAX_ FROM emp;
-- Count Number of Jobs
SELECT COUNT(DISTINCT job) AS N#JOBS FROM emp;
4 Lab 7: SQL
OUTPUT:
4