0% found this document useful (0 votes)
25 views8 pages

DBMS Exp-4

The document describes an experiment on using aggregate functions and views in Oracle 9i. It provides the aim, theory, and code used in the experiment. The theory section explains aggregate functions like COUNT, AVG, MAX, MIN, and how to use GROUP BY and HAVING clauses. It also defines views as logical representations of data from tables that can restrict access and simplify queries. The code section shows examples using aggregate functions, GROUP BY, HAVING, and creating, accessing, and dropping a view. The output and observations discuss the results, and conclusions note how aggregates summarize data and views enhance queries.

Uploaded by

kartikpatil0211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views8 pages

DBMS Exp-4

The document describes an experiment on using aggregate functions and views in Oracle 9i. It provides the aim, theory, and code used in the experiment. The theory section explains aggregate functions like COUNT, AVG, MAX, MIN, and how to use GROUP BY and HAVING clauses. It also defines views as logical representations of data from tables that can restrict access and simplify queries. The code section shows examples using aggregate functions, GROUP BY, HAVING, and creating, accessing, and dropping a view. The output and observations discuss the results, and conclusions note how aggregates summarize data and views enhance queries.

Uploaded by

kartikpatil0211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Experiment No: - 4

Experiment Name: - Practical using Aggregate functions and View.

Aim: - Performing practical by using Aggregate functions and View,

Resource required: - Oracle 9i - iSQLplus

Theory
● AGGREGATING DATA USING GROUP FUNCTIONS:

Group Functions: It operate on sets of rows to give one result per group.
Syntax: SELECT [column,] group_function (column), …
FROM table
[WHERE condition]
[GROUP BY column]
[ORDER BY column];

- Types of Group Functions:


1. AVG, COUNT, MAX, MIN, STDDEV, SUM, and VARIANCE
e.g.: SELECT AVG (salary), MAX (salary), MIN (salary), and SUM (salary)
FROM employees
WHERE job_id LIKE ‘%REP%’;
AVG (SALARY) MAX (SALARY) MIN (SALARY) SUM (SALARY)
8150 11000 6000 32600

2. COUNT (*): returns the number of rows in a table.


e.g.: SELECT COUNT (*)
FROM employees
WHERE department_id = 50;

3. DISTINCT: returns the number of distinct non-null values.


e.g.: SELECT COUNT (DISTINCT department_id)
FROM employees;

● Creating groups of data using GROUP BY clause:


Syntax: SELECT column, group_function (column)
From table
[WHERE condition]
[GROUP BY group_by_expression]
[ORDER BY column];
e.g.: SELECT AVG (salary)
FROM employees
GROUP BY department_id;
● The HAVING Clause: to restrict groups
Syntax: SELECT column, group_function
From table
[WHERE condition]
[GROUP BY group_by_expression]
[HAVING group_condition]
[ORDER BY column];

e.g.: SELECT department_id, MAX (salary)


FROM employees
GROUP BY department_id
HAVING MAX (salary)>10000;
- Displays department numbers and maximum salaries for those departments whose
maximum salary is greater than $10,000.

● Nesting Group Functions:


e.g.: SELECT MAX (AVG (salary))
FROM employees
GROUP BY department_id;

● VIEWS:
- Logically represents subsets of data from one or more tables. Why it is used:
- To restrict data access.
- To make complex queries easy
- To represent different views of the same data.

Creating a View:
Syntax: CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view
[(alias [, alias]…)]
AS subquery
[WITH CHECK OPTION [CONSTRAINT constraint]]
[WITH READ ONLY [CONSTRAINT constraint]]; e.g.:
CREATE VIEW empvu80
AS SELECT employee_id, last-name, salary
FROM employees
WHERE DEPARTMENT_ID=80;
Removing data from View:
e.g.: SELECT * FROM empvu80;
Removing View:
Syntax: DROP VIEW view; e.g.:
DROP VIEWempvu80

PART B

Roll No.: A-46 Name: Ritesh Pawar


Class: SE Batch: A3
Date Of Experiment: 07/02/2024 Date Of Submission: 18/02/2024
Grade:

B.1 CODE
1. AVG, COUNT, MAX, MIN CODE
USE EXP1;
SELECT AVG(SALARY), MAX(SALARY), MIN(SALARY), SUM(SALARY) FROM
EMPLOYEE;
2. COUNT
2a) USE EXP1;
SELECT COUNT (*) FROM EMPLOYEE;
2b) DISTINCT COUNT
USE EXP1;
SELECT DISTINCT JOBID, FIRSTNAME, LASTNAME FROM EMPLOYEE;
3. GROUP BY CLAUSE
USE EXP1;
SELECT AVG(SALARY), FIRSTNAME FROM EMPLOYEE GROUP BY FIRSTNAME;
4. HAVING CLAUSE
USE EXP1;
SELECT JOBID, MAX(SALARY) FROM EMPLOYEE GROUP BY JOBID HAVING
MAX(SALARY)>80000;
5. VIEW
a) To create view
USE EXP1;
CREATE VIEW EMP_HIGH_SALARY AS
SELECT EMPID, FIRSTNAME, LASTNAME, SALARY FROM EMPLOYEE WHERE
SALARY > 90000;
b) To access view table
USE EXP1;
SELECT * FROM EMP_HIGH_SALARY;
c) To delete view table
USE EXP 1
DROP VIEW EMP_HIGH_SALARY;

B.2 OUTPUT
1. AVG, COUNT, MAX, MIN CODE

2a) COUNT
2b) DISTINCT COUNT

3. GROUP BY CLAUSE
4. HAVING CLAUSE

5. VIEW
a) To create view
b) To access view table

c) To delete view table

B.3 OBSERVATIONS:
In this experiment, Aggregate functions such as SUM, AVG, COUNT, MIN, MAX, ORDER
BY CLAUSE AND HAVING CLAUSE efficiently process large datasets, summarizing data
according to specified criteria. Also, creating Views simplified complex queries by
encapsulating them into reusable virtual tables, enhancing query readability and
maintainability.

B.4 CONCLUSIONS:
In conclusion, the experiment highlighted the usefulness of aggregate functions for data
summarization and views for simplifying complex queries in SQL. These tools are crucial for
efficient data analysis and management in relational databases.

You might also like