A24 Exp04 DBMS
A24 Exp04 DBMS
Experiment No: - 4
Experiment Name: - Practical using Aggregate functions and View.
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];
15
Mumbai University
Vidyavardhini’s College of Engineering and Technology, Vasai
• 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
16
Mumbai University
Vidyavardhini’s College of Engineering and Technology, Vasai
e.g.: SELECT *
FROM empvu80; Removing View:
Conclusion:
You should have learned how to use joins to display data from multiple tables, group
functions and views.
2. Determine the count of the Number of managers without actually listing them. Label the
column Number of Managers.
3. Create a view called EMPLOYEES_VU based on the employee numbers, employee names,
and department numbers from the EMPLOYEE table. Changes the heading for the employee
name to EMPLOYEE. And Display the contents of the EMPLOYEE_VU view.
4. Select the view name and text from the USER_VIEWS data dictionary view.
CODE:
17
Mumbai University
Vidyavardhini’s College of Engineering and Technology, Vasai
SELECT *
FROM employ
CROSS JOIN DEPARTMENTS;
SELECT last_name,
department_name,
location_id,
city
FROM employ
WHERE commision IS NOT NULL;
18
Mumbai University
Vidyavardhini’s College of Engineering and Technology, Vasai
SELECT employ.employee_id,
employ.last_name,
employ.job_id,
employ.department_id,
employ.salary,
DEPARTMENTS.department_name,
DEPARTMENTS.location
FROM employ
LEFT OUTER JOIN DEPARTMENTS
ON employ.department_id = DEPARTMENTS.department_id;
--ASSIGNMENT 4
SELECT
MAX(salary) AS "Maximum",
MIN(salary) AS "Minimum",
SUM(salary) AS "Sum",
AVG(salary) AS "Average"
FROM employ;
19
Mumbai University
Vidyavardhini’s College of Engineering and Technology, Vasai
--experiment 4
SELECT department_id,
SUM(salary) AS total_salary
FROM employ
GROUP BY department_id
HAVING SUM(salary) > 50000;
OUTPUT:
20
Mumbai University
Vidyavardhini’s College of Engineering and Technology, Vasai
21