As we all know, the SQL command "CREATE TABLE as select" does not support "order by", but if we want to add a table, it stores a group of data that has been arranged, what should I do if the data comes from an existing table? Haha, it's a good idea to create a view first and then create again. Let's take a look at the following article.ArticleAnd may be useful to you. Generally, sorting data in a table is helpful to optimize the query performance of the database. For example, your applicationProgramA Query Needs to be executed frequently. Select * from EMP where name like'm % '; If all rows in the EMP table are sorted by their names, your query will be significantly improved. Because all the rows whose names contain 'M' are stored together, Oracle only obtains a small amount of data blocks from the table when querying data. Of course, if the data in your table is static, this is very good, that is, you can insert in order when you create a table. However, data in our table is often updated, and SQL does not support insert into with the order by clause... select... from... and create table as select... from... command, so we can only discard the inherent sorting. When the data reaches tens of thousands of records, the query performance is significantly reduced. There are two solutions to this problem. Here we provide a method to do this through the group by operation. Create view empgroup Select name, empid, hiredate, rownum from EMP Group by name, empid, hiredate, rownum; Use this view to add a table Create Table sorted_emp as select name, empid, hiredate from empgroup; Note: 1. If you use oracle7.3 or later, you can use inline view instead of empgroup view. 2. If you ignore rownum when creating a view, a large number of repeated records will appear due to the use of group. |