Oracle Learning 3

Source: Internet
Author: User

Inquire

1. GROUP BY

2. Basic functions

AVG (product mean) AVG (column_name) for this column of the product mean value

SUM (sum) sum (column_name) The sum of this column

Max (max) max (column_name) to find the maximum value in this column

Min (min) min (colunm_name) to find the minimum value of this column

Count (total) count (*), COUNT (column_name) number of rows in this column, COUNT (distinct column_name) to Redo row count

Wm_concat (row to column)

NVL (Column_name,default) NULL function returns default when COLUMN_NAME is empty

3. GROUP BY

(1) Check the Department of goods are wages:

Select Deptno,avg (SAL) from the EMP group by DEPTNO;

Select AVG (SAL) from the EMP group by DEPTNO;

In grouping queries group BY, columns that are not included in the group function are unloaded after the GROUP BY clause, and the columns that are included with group by do not have to be included in the select list.

(2) According to the Department of different positions to the statisticians work goods are wages:

Select Deptno,job,avg (SAL) from the EMP Group by Deptno,job ORDER by Deptno;

Group BY columns are grouped in order, that is, the first column is first installed and then grouped in the second column and so on.

4. HAVING clause

For departments with a salary greater than 2000 of the department's products:

Select Deptno,avg (SAL) from EMP GROUP BY DEPTNO has avg (SAL) > 2000;

The difference between where and having:

1. You cannot use the group functions, such as AVG, Sum, in the WHERE clause, and can be used in the HAVING clause.

2, where is the first filter after the group, having the first group after filtering.

(from the SQL optimization point of view: if where and having both can be used, the where is preferred)

5. Group BY enhancement

(1) Select Deptno,job,sum (SAL) from the EMP group by Deptno,job;

(2) Select Deptno,sum (SAL) from the EMP group by DEPTNO;

(3) Select sum (SAL) from EMP;

(4) Select Deptno,job,sum (SAL) from the EMP Group by Rollup (Deptno,job);

(1) + (2) + (3) = (4)

Oracle Learning 3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.