0% found this document useful (0 votes)
2 views

Lab 09

SQL Function queries

Uploaded by

melaibaabbas
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab 09

SQL Function queries

Uploaded by

melaibaabbas
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Database Systems Lab

IT[244]
Lab #:09

FACULTY OF CS & IT

UNIVERSITY OF GUJRAT
SQL Functions
• SQL functions can be used to do the
followings.
– Perform calculations on data.
– Modify individual data items.
– Manipulate output for group of rows.
– Format dates and number for display.
– Convert column data types.

SQL functions may accepts arguments and always


return a value.
Types of SQL functions.
SQL Aggregate functions
Aggregate functions are also called the
group function.
Perform a calculation on a set of values
and return a single value.
SQL Aggregate functions
By using the SQL Aggregate function, we
can perform the different functions on
columns
1. AVG
2. COUNT
3. MAX
4. MIN
5. SUM
Using the SUM Function
The Sum function will return the sum value
of column

SQL> SELECT SUM(sal)


2 FROM emp
3 WHERE deptno = 20;
Using the AVG Function
The AVG function will return the Average
value of column

SQL> SELECT AVG(sal)


2 FROM emp
3 WHERE deptno = 20;
Using the NVL Function
with Group Functions

• The NVL function forces group functions to


include null values.

SQL> SELECT AVG(NVL(comm,0))


2 FROM emp;

AVG(NVL(COMM,0))
----------------
157.14286
Using the Count Function
The Count function will return the Average
value of column

SQL> SELECT COUNT(sal)


2 FROM emp;
Using the MAX Function
The MAX function will return the
Maximum value of column

SQL> SELECT MAX(sal)


2 FROM emp;
Using the MIN Function
The MIN function will return the Minimum
value of column

SQL> SELECT MIN(sal)


2 FROM emp;
Using Group Function,
group by clause
Using Group Function Functions
Using Group Function,
Having clause
Using the HAVING Clause

SQL> SELECT job, SUM(sal) PAYROLL


2 FROM emp
3 WHERE job NOT LIKE 'SALES%'
4 GROUP BY job
5 HAVING SUM(sal)>5000
6 ORDER BY SUM(sal);

JOB PAYROLL
--------- ---------
ANALYST 6000
MANAGER 8275

You might also like