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