[英]Sort a mysql table, drop it and create new one sorted
I have a table with the following structure: 我有一个具有以下结构的表:
country, city, population 国家,城市,人口
The table is alphabetically sorted by city, I want to sort by population desc and create a new table that is sorted this way. 该表按字母顺序按城市排序,我想按人口desc排序并创建一个按此方式排序的新表。
What would be the query to be used in this case? 在这种情况下要使用的查询是什么?
您可以使用单个查询获得所需的结果:
Create table new_table select * from table order by population desc;
I don't understand why you would need to do this when you can just: 我不明白为什么你需要这样做才能做到:
select country, city, population from table order by population desc;
To answer you question: 回答你的问题:
create table new_table like table;
insert into new_table select * from table order by population desc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.