0% found this document useful (0 votes)
14 views

DBMS Exp5

The document describes using various SQL aggregate functions, numeric functions, and date functions to analyze sample employee data, including finding averages, minimums, maximums, and totals. It also covers the GROUP BY and HAVING clauses to group and filter results. The student is given 25 practice questions demonstrating different ways to query the employee data using these SQL features.

Uploaded by

h8000728909
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

DBMS Exp5

The document describes using various SQL aggregate functions, numeric functions, and date functions to analyze sample employee data, including finding averages, minimums, maximums, and totals. It also covers the GROUP BY and HAVING clauses to group and filter results. The student is given 25 practice questions demonstrating different ways to query the employee data using these SQL features.

Uploaded by

h8000728909
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Experiment # 5

Date of Performance:- 25 / 1 /2024 Date of Submission:- 31 / 1 /2024


Class:- MBA Tech/ Btech Division:A3
Student SAP Id:-70552200088
Student Roll No:-E284
Student Name:- Jayaditya Arora

Aim:

1. To perform SQL Aggregate Functions, Numeric Function, Date functions.


2. Group by Clause

Part A

Aim:SQL commands:

1. To perform SQL Aggregate Functions, Numeric Function, Date functions.


2. Group by Clause
Prerequisite:Oracle.

Outcome: Understanding and use of various Oracle functions.


Theory:

Aggregate Functions

AVG: returns average value

Avg(<ColumnName>)

MIN: returns minimum value

min(<ColumnName>)

COUNT: returns no of rows where expression is not NULL

count(<ColumnName>)

COUNT(*): returns no of rows in the table including duplicates and those with NULL

count(*)

MAX: returns maximum value

max(<ColumnName>)

SUM: returns sum of the values

sum(<ColumnName>)

Numeric Functions

ABS: returns the absolute value of n

abs(n)

POWER: returns m raised to nth power


power(m,n)

ROUND: returns n rounded to m places to the right of the decimal point

round(n,m)

SQRT: returns square root of n

sqrt(n)

EXP: returns e raised to nth power

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: returns a random number or a random number within a range.

Rand()

Rand()*(upper value-lower value) e.g. rand()*(10-1)

String Functions:

LEN: returns the length of the specified string.


LEN( string )

CONCAT: allows you to concatenate strings together.


CONCAT( string1, string2, ... string_n )

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.

DATEADD( interval, number, date )

 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

 Number: The number of intervals that you wish to add.


 Date: The date to which the interval should be added.

DATEDIFF: returns the difference between two date values, based on the interval specified.

DATEDIFF( interval, date1, date2 )

DATEPART: returns a specified part of a given date, as an integer value.

DATEPART( interval, date )

DATENAME: returns a specified part of a given date, as a string value.

DATENAME( interval, date )

YEAR: returns a four-digit year (as a number) given a date value.

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.

Select <columnname 1><columnname 2>...<columnname n>,

Aggregate_function(<expression>) from tablename Where <condition>

Group by <columnname 1><columnname 2>...<columnname n>;

Having clause: imposes a condition on group by clause.

Select <columnname 1><columnname 2>...<columnname n>,

Aggregate_function(<expression>) from tablename Where <condition>

Group by <columnname 1><columnname 2>...<columnname n>

Having <condition>;

Procedure:

1. Formulate the query for given problem.


2. Write the SQL query with proper input.
3. Execute the query.

Practice Exercise:

1. Give one example query to demonstrate each function.


2. Display the total expenditure of company on the salary of employees.
3. Find average salary of clerks.
4. Find average salary of managers and salesman.
5. Find employee with maximum annual income.
6. Find the employee with minimum monthly income.
7. List the emps in the asc order of Designations of those joined after the second half of
1981.
8. Find the number of employee earning more than average salary of employees.
9. List the emps along with their Experience whose Daily Sal is more than Rs.100.
10. List all the employees order by their seniority.
11. List the emps who joined on 1-MAY-81,3-DEC-81,17-DEC-81,19-JAN-80 in asc
order of seniority.
12. List all the emps who joined before or after 1981.
13. List the emps who are joined in the year 81.
14. List the emps who are joined in the month of Aug 1980.
15. List the emps those who joined in 80’s.
16. Find the average of experience of all clerks (both ceil and floor value).
17. List the emps who joined in January.
18. List the emps who have completed 10 years today.
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

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:

1. Write and execute the query in Oracle SQL server/oracle 10g.


2. Paste the snapshot of the output in input & output section.

Part B

Date of Performance:- 25 / 1/2024 Date of Submission:- 31/1/24


Student SAP Id:- /2017
Student Roll No:-
Student Name:-
Grade:

Observation & Learning:

In this we have lean about agreeagate function .

Conclusion:

We can use simple things instead of complexing with using different commands or
queries.

Output and input:


2]

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:

1. What is the use of aggregate function?


 Aggregate functions in SQL are used to perform a calculation on a set of values and
return a single value. They are often applied to a column of data to summarize
information, such as calculating the sum, average, count, maximum, or minimum.
Examples of aggregate functions include SUM(), AVG(), COUNT(), MAX(), and
MIN().
2. How different numbers of rows can be counted?
 The COUNT() function in SQL is used to count the number of rows in a result set. The
way you use it depends on your requirement:
 COUNT(*): Counts all rows in a table, including rows with NULL values.
 COUNT(column_name): Counts the number of non-NULL values in a specific
column.
 COUNT(DISTINCT column_name): Counts the number of unique, non-NULL
values in a specific column.
3. What is the difference between the HAVING and WHERE clause?
 The WHERE clause is used in SQL to filter rows before they are grouped and
aggregated. It is applied before the GROUP BY clause in a query.

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

You might also like