DBMS Exp5
DBMS Exp5
Aim:
Part A
Aim:SQL commands:
Aggregate Functions
Avg(<ColumnName>)
min(<ColumnName>)
count(<ColumnName>)
COUNT(*): returns no of rows in the table including duplicates and those with NULL
count(*)
max(<ColumnName>)
sum(<ColumnName>)
Numeric Functions
abs(n)
round(n,m)
sqrt(n)
exp(n)
FLOOR: returns the largest integer value that is equal to or less than a number
floor(n)
CEILING: returns the smallest integer value that is equal to or greater than a number
ceiling(n)
Rand()
String Functions:
LOWER: converts all letters in the specified string to lowercase (same for Upper).
LOWER( string )
Date Functions:
CURRENT_TIMESTAMP: returns the current date and time (GETDATE function can also
be used).
CURRENT_TIMESTAMP
DATEADD: returns a date after which a certain time/date interval has been added.
Interval: The time/date interval that you wish to add. It can be one of the following
values:
Year, quarter, month, day, week, hour, minute, second
DATEDIFF: returns the difference between two date values, based on the interval specified.
YEAR( date_value )
MONTH: returns the month (a number from 1 to 12) given a date value.
MONTH( date_value )
DAY: returns the day of the month (a number from 1 to 31) given a date value.
DAY( date_value )
Group by clause: this optional clause tells Oracle to group rows based on distinct values that
exists for specified columns.
Having <condition>;
Procedure:
Practice Exercise:
19. List the employees who are senior to most recently hired employee working under
king.
20. List the employees who joined in 1981 with the job same as the most senior person of
the year 1981.
21. List the details of the department where maximum number of emps are working.
22. Find the total salary department wise.
23. Find total salary average salary Job wise.
24. Find the name of department taking maximum salary.
25. Find name of department taking minimum salary.
Instructions:
Part B
Conclusion:
We can use simple things instead of complexing with using different commands or
queries.
6
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Student Manual Lab Manual (Part-B) Academic Year- 2021-
2021
Year:-Second Subject:- DBMS Semester:- third
3]
4]
5]
6]
7
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Student Manual Lab Manual (Part-B) Academic Year- 2021-
2021
Year:-Second Subject:- DBMS Semester:- third
7]
8]
9]
SELECT EMP_NO,ENAME,salary / 240.0 AS daily_sal, DATEDIFF(CURDATE(), HIREDATE) AS
experience_in_years FROM Emp WHERE Salary > 100;
10]
11]
12]
8
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Student Manual Lab Manual (Part-B) Academic Year- 2021-
2021
Year:-Second Subject:- DBMS Semester:- third
13]
14]
15]
16]
17]
9
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Student Manual Lab Manual (Part-B) Academic Year- 2021-
2021
Year:-Second Subject:- DBMS Semester:- third
18]
19]
21]
22]
23]
10
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Student Manual Lab Manual (Part-B) Academic Year- 2021-
2021
Year:-Second Subject:- DBMS Semester:- third
24]
25]
Questions:
11
SVKM’s NMIMS
Mukesh Patel School of Technology Management & Engineering Shirpur Campus
Deparment of Computer Engineering
Student Manual Lab Manual (Part-B) Academic Year- 2021-
2021
Year:-Second Subject:- DBMS Semester:- third
The HAVING clause, on the other hand, is used to filter the results of a GROUP BY
query after the grouping and aggregation have taken place. It is essentially a WHERE
clause for grouped data.
4. Does the WHERE clause work with aggregate functions?
Yes, the WHERE clause works with aggregate functions when filtering rows before they
are aggregated. For example, you can use a WHERE clause to filter the rows that will be
included in the calculation of the SUM(), AVG(), or other aggregate functions. However,
if you want to filter the aggregated results, you should use the HAVING clause instead,
as the WHERE clause filters rows before aggregation, while the HAVING clause filters
aggregated results after the grouping and aggregation process.
1.
12