Oracle sql query using avg, count, max and min

cms technology web page configuration drupal web site
Setup and configuration of cms and drupal web site

 

SQL> select avg(sal)
2 from emp
3 group by sal;

AVG(SAL)
----------
800
950
1100
1250
1300
1500
1600
2450
2850
2975
3000
5000
SQL> select count(sal)from emp;

COUNT(SAL)
----------
14
SQL> select avg(sal) from emp;

AVG(SAL)
----------
2073.21429
SQL>

 

SQL> save salstats
Created file salstats.sql
SQL> edit salstats

select count(sal) from emp;
select avg(sal) from emp;
select min(sal) from emp;
select max(sal) from emp;

count avg min max

SQL> start salstats

COUNT(SAL)
----------
14

AVG(SAL)
----------
2073.21429

MIN(SAL)
----------
800

MAX(SAL)
----------
5000
SQL>

 

EXAMPLE2:

 

SQL> edit salstats2

clear scr

ttitle left "Employee Salary statistics"

SELECT
(select count(sal) from emp) as "NO of Emp.",
(select avg(sal) from emp) as "Average",
(select max(sal) from emp) as "Highest",
(select min(sal) from emp) as "Lowest",
(select max(sal) from emp) - (select min(sal) from emp) as "HI/LO"
FROM
dual;


count avg and hi lo

 

The output result:

SQL> start salstats2


Employee Salary statistics
NO of Emp. Average Highest Lowest HI/LO
---------- ---------- ---------- ---------- ----------
14 2073.21429 5000 800 4200
SQL>

 


AttachmentSize
salstats.sql_.txt112 bytes
salstats2.sql_.txt327 bytes

Custom Search