PRACTICAL NO-5 To Study Aggregate Functions With Query.
PRACTICAL NO-5 To Study Aggregate Functions With Query.
An aggregate function is a function that performs a calculation on a set of values, and returns a single
value.
Aggregate functions are often used with the GROUP BY clause of the SELECT statement. The GROUP
BY clause splits the result-set into groups of values and the aggregate function can be used to return
a single value for each group.
1. COUNT() Function
Syntax:
COUNT(*)
or
2. SUM() Function
Syntax:
SUM()
or
3. AVG() Function
Syntax:
AVG()
or
4. MIN() Function
The MIN() aggregate function returns the lowest value (minimum) in a set of non-NULL values.
Syntax:
MIN()
or
5. MAX() Function
The MAX() aggregate function returns the highest value (maximum) in a set of non-NULL values.
Syntax:
AVG()
or
(6) Create table supplier from employee with all the columns.
Query: CREATE TABLE SUPPLIER (EMP_NO,EMP_NAME,EMP_SAL) AS SELECT
EMP_NO,EMP_NAME,EMP_SAL FROM EMPLOYEE;
Output: EMP_NO EMP_NAME EMP_SAL
101 Smith 800
102 Snehal 1600
(7) Create table sup1 from employee with first two columns.
Query: CREATE TABLE SUP1 (EMP_NO,EMP_NAME) AS SELECT EMP_NO,EMP_NAME FROM
EMPLOYEE;
Output: EMP_NO EMP_NAME
101 Smith
102 Snehal
(9) Insert the data into sup2 from employee whose second character should be ‘n’ and string
should be 5 characters long in employee name field.
Query:INSERT INTO SUP2(EMP_NO,EMP_NAME,EMP_SAL) SELECT EMP_NO,EMP_NAME,EMP_SAL
WHERE EMP_NAME '_n___';
Output: -------------------------------------
(14) Update the value dept_no to 10 where second character of emp. name is ‘m’.
Query: UPDATE EMPLOYEE SET DEPT_NO=10 WHERE EMP_NAME LIKE ('_m%');
Output: EMP_NAME DEPT_NO
Rmaj 10
(15) Update the value of employee name whose employee number is 103.
Query:UPDATE EMPLOYEE SET EMP_NAME='RAM' WHERE EMP_NO=103;
Output: EMP_NAME EMP_NO
RAM 103