The format and execution sequence analysis of simple query statements in Oracle

Source: Internet
Author: User

A simple query SQL format is as follows:

SELECT ...

From ....

[WHERE ...] --Filter Line

[GROUP by ... [Having ...] --group by groups The results of the previous where condition filtering, having a filter row group

  

[ORDER by ...] --Sort the results

Eg: now there is a exchangetime table, the table structure is as follows

is the name empty? Type
----------------------------------------------- -------- --------------------------------
ID not NULL number (18)
System_type not NULL CHAR (1)
Time_kind not NULL number (10)
Time_name not NULL VARCHAR2 (16)
Begin_time not NULL number (10)
End_time not NULL number (10)

The query statements and results are as follows:

Sql> List

1 Select T.system_type, AVG (t.begin_time) from Exchangetime t

2 Where T.id < 10

3 GROUP BY T.system_type

4 having AVG (t.begin_time) >110000

5* ORDER BY System_type

Sql>/

System_type AVG (T.begin_time)

------------ -----------------

0 110750

1 150000

Sql> Spool Off

In the above query, where T.id < 10 first filters the records in the Exchagetime, the filtered rows are grouped by group by System_type, and the HAVING clause filters the row groups, preserving only avg (T.begin _time) >110000 Line, the last order by statement follows the System_type field to sort the results in ascending order to get the final result.

Ps:1, group by can be followed without having, but must be used in conjunction with the GROUP BY statement if there is a HAVING clause

2. Where clause can only filter a single line and cannot filter row groups, the filter row group must use a HAVING clause, such as where AVG (T.begin_time) is wrong. The row group must be filtered with having, like the above statement.

  

The format and execution sequence analysis of simple query statements in Oracle

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.