0% found this document useful (0 votes)
89 views5 pages

Dbms Lab (Experiment - 2) : 1. Write Sample Queries On Aggregate Functions (Min, Max, Count, Sum, Avg)

The document describes sample queries using aggregate functions such as MIN, MAX, COUNT, AVG, and SUM on the myemp table. It also provides examples of set operations including UNION, UNION ALL, INTERSECT, and MINUS used on two sample tables. Syntax and descriptions are given for each function and operation.

Uploaded by

sarala devi
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)
89 views5 pages

Dbms Lab (Experiment - 2) : 1. Write Sample Queries On Aggregate Functions (Min, Max, Count, Sum, Avg)

The document describes sample queries using aggregate functions such as MIN, MAX, COUNT, AVG, and SUM on the myemp table. It also provides examples of set operations including UNION, UNION ALL, INTERSECT, and MINUS used on two sample tables. Syntax and descriptions are given for each function and operation.

Uploaded by

sarala devi
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/ 5

DBMS LAB

(EXPERIMENT _2)
1. Write sample queries on aggregate functions ( min,max,count, sum,avg).

Table used :

a) MIN ( )

Description : The MIN( ) function returns the smallest value of the selected column.
Syntax : MIN(column_name)
Example Query : select MIN(sal) from myemp;
Output :

b) MAX ( )

Description: The MAX( ) function returns the smallest value of the selected column.
Syntax : MAX(column_name)
Example Query : select MAX(sal) from myemp;
Output :

c) COUNT ( )

Description: The COUNT( ) function returns the number of rows that matches a
specified criteria.
Syntax : SELECT COUNT( column_name )
FROM table_name
WHERE condition ;
Example Query : SELECT COUNT (job)
FROM myemp
WHERE job= 'CLERK';
Output :

d) AVG ( )

Description: The AVG( ) function returns the average value of a numeric column..
Syntax : SELECT AVG(column_name)
FROM table_name
WHERE condition ;
Example Query : select AVG(sal)
from myemp;
Output :

e) SUM ( )

Description: The SUM( ) function returns the total sum of a numeric column.
Syntax : SELECT SUM(column_name)
FROM table_name
WHERE condition ;
Example Query : SELECT SUM(sal)
FROM myemp
WHERE job= 'CLERK' ;
Output :
2. Write sample queries on set Operations ( union , intersect and Minus)

Tables used :

1) Table 1:

2) Table 2:

a) UNION

Description : UNION is used to combine the results of two or more SELECT


statements.
Syntax : SELECT column_list_1
FROM table_1
UNION
SELECT column_list_1
FROM Table_2;
Example Query : select * from table_1
UNION
select * from table_2;

Output :
b) UNION ALL

Description : UNION ALL is also used to combine the results of two or more
SELECT statements.However it includes all the duplicate rows also.
Syntax : SELECT column_list_1
FROM table_1
UNION ALL
SELECT column_list_1
FROM Table_2;
Example Query : select * from table_1
UNION ALL
select * from table_2;

Output :

c) INTERSECT

Description :Intersect operation is used to combine two SELECT statements, but it


only retuns the records which are common from
both SELECT statements. In case of Intersect the number of
columns and datatype must be same..
Syntax : SELECT column_list_1
FROM table_1
INTERSECT
SELECT column_list_1
FROM Table_2;
Example Query : select * from table_1
INTERSECT
select * from table_2;

Output :
d) MINUS

Description : The Minus operation combines results of two SELECT statements and
return only those in the final result, which belongs to the first set of
the result.
Syntax : SELECT column_list_1
FROM table_1
MINUS
SELECT column_list_1
FROM Table_2;
Example Query : select * from table_1
MINUS
select * from table_2;

Output :

You might also like