Dbms Lab (Experiment - 2) : 1. Write Sample Queries On Aggregate Functions (Min, Max, Count, Sum, Avg)
Dbms Lab (Experiment - 2) : 1. Write Sample Queries On Aggregate Functions (Min, Max, Count, Sum, Avg)
(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
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
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 :