oracle database study notes (six)

Chapter VI Multiple Row Functions multi-valued function

Category database functions:
. 1) Single Row Functions single-valued function
characteristics: n pieces of data involved in the function operation to obtain n results.
2) Multiple Row Functions multivalued function (group function)
Features: n pieces of data involved in the function calculation, the result may be less than n.
Calculation of the process to the data packet.
A class 48 students, each a Group 8, 6 into six groups.
Calculating the average score for each team?

1. The common multi-valued function
avg calculating an average value
max maximum value calculation
min computes the minimum
sum and computing the algebraic
number of non-null value of a field count field calculated

insert into s_emp(id,last_name)
values(999,'_briup');

select count(*) from s_emp;
-->25 √

2. Syntax multivalued function
key:
. 1) group by
specifies field of the packet,
e.g. group by field A,
then the value of the field will be the same data into a set of A.
2) having
to specify the search criteria after a packet (similar function where)

Position:
. 1) appears after the Group by a where clause.
2) having the group by appear behind.

select query in six keywords:
select ...
from ...
the WHERE ...
Group by ...
the HAVING ...
the Order by ...;

Syntax:
SELECT function name (field being computed)
from table
[group by grouping field]
[HAVING query packet after];
group by and having can not occur.
group by does not appear, on behalf of the entire table all the data into a large group.
Eventually only get a calculation result.
having all the data does not appear on behalf of all output.

For example:
query the average salary for each department?
AVG SELECT (the salary)
from s_emp
Group by the dept_id;

Query the average wage for all employees?
AVG SELECT (the salary)
from s_emp;

Query the average salary for each department, the highest wages, the minimum wage?
the dept_id SELECT, AVG (the salary), max (the salary), min (the salary)
from s_emp
Group by the dept_id;

Note:
1) select occur later in the field,
either set of functions, either grouped by field.
2) and having the difference between where
where is before the packets, the data value of a single query limit.
After having a packet, a set of functions performed,
the results produced by the set of functions to be limiting.

 

 

 

Guess you like

Origin www.cnblogs.com/DennySmith/p/12189204.html