简体   繁体   English

SQL 排序和更新字母数字列

[英]SQL Sort and update alpha numeric column

I have a column that is alphanumeric and I ordered it and everything is all right.我有一个字母数字列,我订购了它,一切正常。 My problem is that the result of alpha numeric column look like this when some classes are missing in the select query:我的问题是,当“ select查询”中缺少某些类时,alpha数字列的结果看起来如此:

02 - buyers
03 - sellers
05 - customers
07 - xxxx
12 - yyyyyy

How can I reorder this with the right order:我如何以正确的顺序重新排序:

01 - buyers
02 - sellers
03 - customers
04 - xxxx
05 - yyyyyy

Thanks.谢谢。

use a temporary table with an auto-id field.使用带有 auto-id 字段的临时表。

create table tmpNumTable(id INT NOT NULL AUTO_INCREMENT, name String)

insert into tmpNumTable(name) select name from clientType

select * from tmpNumTable

The syntax may differ depending on the language.语法可能因语言而异。

https://dev.mysql.com/doc/refman/8.0/en/create-table.html https://dev.mysql.com/doc/refman/8.0/en/insert-select.html https://dev.mysql.com/doc/refman/8.0/en/create-table.html https://dev.mysql.com/doc/refman/8.0/en/insert-select.html

Is this what you want?这是你想要的吗?

select row_number() over (order by col1), col2
from t
order by col1;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM