200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 数据库中文字段按拼音排序

数据库中文字段按拼音排序

时间:2020-01-05 19:19:07

相关推荐

数据库中文字段按拼音排序

使用 order by convert_to(city, ‘GBK’) 方式按中文字典顺序排序, 测试如下:

create table public.test_city(id bigserial primary key, city char(10));test#\d jinbo.test_city;Table "public.test_city"Column |Type|Modifiers --------+---------------+--------------------------------------------------------------id| bigint | not null default nextval('public.test_city_id_seq'::regclass)city | character(10) | Indexes:"test_city_pkey" PRIMARY KEY, btree (id)test=# insert INTO public.test_city(city) values ('上海'),('北京'),('广州');INSERT 0 3test=# insert INTO public.test_city(city) values ('西安'),('榆林'),('三亚');INSERT 0 3test=# insert INTO public.test_city(city) values ('深圳'),('鞍山'),('昆明');INSERT 0 3test=# insert INTO public.test_city(city) values ('大连'),('青岛'),('成都');INSERT 0 3test=# select * from public.test_city;id |city----+--------------1 | 上海 2 | 北京 3 | 广州 4 | 西安 5 | 榆林 6 | 三亚 7 | 深圳 8 | 鞍山 9 | 昆明 10 | 大连 11 | 青岛 12 | 成都 (12 rows)test=# select * from public.test_city order by convert_to(city, 'GBK');id |city----+--------------8 | 鞍山 2 | 北京 12 | 成都 10 | 大连 3 | 广州 9 | 昆明 11 | 青岛 6 | 三亚 1 | 上海 7 | 深圳 4 | 西安 5 | 榆林 (12 rows)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。