DBMS Lab4 Assignment
DBMS Lab4 Assignment
semester)
Title: Inbuilt Functions
Objective: To practice and implement in-built functions to be executed using DML
Theory:
SQL Command:
Numeric function:
Character function:
Count function
• COUNT(*): counts all, inclusive of duplicates and null values
o Select count(*) FROM employee
• COUNT(col_name): avoids null value
o Select count(salary) FROM employee
• COUNT(distinct col_name): avoids repeated and null values
o Select count(distinct salary) FROM employee
1. Group function
• AVG()
▪ Select avg(salary) FROM employee
• MAX()
▪ Select max(salary) FROM employee
• MIN()
▪ Select min(salary) FROM employee
• SUM()
▪ Select sum(salary) FROM employee
➢ GROUP BY clause
• Allows us to use simultaneous column name and group function
• Use in conjunction with the aggregate functions to group the result-set by one or
more columns.
• E.g.: select max(salary), job FROM employee group by job
➢ HAVING clause
• Use to specify conditions on rows retrieved by using group by clause.
• Added to SQL because the WHERE keyword could not be used with aggregate
functions.
• E.g. : select max(salary), job FROM employee group by job having count(*)>=2
Lab Exercise:
Numeric Function:
1.
Query:
SELECT ABS(-10) FROM employee
Output:
2.
Query:
SELECT CEIL(55.6) FROM employee
Output:
3.
Query:
SELECT FLOOR(55.6) FROM employee
Output:
4.
Query:
SELECT exp(eid) FROM employee
Output:
5.
Query:
SELECT power(4,eid) FROM employee
Output:
6.
Query:
SELECT mod(10,3) FROM employee
Output:
7.
Query:
SELECT sqrt(salary) FROM employee
Output:
8.
Query:
SELECT round(100.2686,2) FROM employee
Output:
Character Function:
9.
Query:
SELECT lower(name) FROM employee
Output:
10.
Query:
SELECT upper(name) FROM employee
Output:
11.
Query:
SELECT ltrim(“ name”) FROM employee
Output:
12.
Query:
SELECT rtrim(“ name ”)FROM employee
Output:
13.
Query:
SELECT REPLACE(name,”Ram”,”Shyam”) FROM employee
Output:
14.
Query:
SELECT substring(designation,2,3) FROM employee
Output:
Count Function:
15.
Query:
SELECT count(*) FROM employee
Output:
16.
Query:
SELECT count(eid) FROM employee
Output:
Group Function:
17.
Query:
SELECT AVG(salary) FROM employee
Output:
18.
Query:
SELECT MAX(salary) FROM employee
Output:
19.
Query:
SELECT MIN(salary) FROM employee
Output:
20.
Query:
SELECT SUM(salary) FROM employee WHERE designation=”programmer”
Output:
21.
Query:
SELECT MAX(salary) FROM employee WHERE designation=”developer”
Output:
Group By Clause:
22.
Query:
SELECT MAX(salary),designation FROM employee GROUP BY designation
Output:
Having Clause
23.
Query:
SELECT MIN(salary),designation FROM employee GROUP BY designation HAVING
count(*)>=2
Output:
Conclusion:
In this way we can implement in-built function to be executed using DML.