数据排序 select from teledbpg order by md5(nickname); id nickname + 1 hello,pgxc 3 pg 1 teledb (3 rows) 排序也能用子查询。 plaintext teledb select from teledbpg order by (select id from teledbpg order by random() limit 1); id nickname + 1 teledb 1 hello,pgxc 3 pg (3 rows) null 值排序结果处理 plaintext teledb insert into teledbpg values(4,null); INSERT 0 1 null 值记录排在最前面。 plaintext teledb select from teledbpg order by nickname nulls first; id nickname + 4 1 hello,pgxc 3 pg 1 teledb (4 rows) null 值记录排在最后。 plaintext teledb select from teledbpg order by nickname nulls last; id nickname + 1 hello,pgxc 3 pg 1 teledb 4 (4 rows) 按拼音排序 使用convert 函数实现汉字按拼音进行排序。 plaintext teledb select from (values ('张三'), ('李四'),('陈五')) t(myname) order by convert(myname::bytea,'UTF8','GBK'); myname 陈五 李四 张三 (3 rows) 使用convertto 函数实现汉字按拼音进行排序。 plaintext teledb select from (values ('张三'), ('李四'),('陈五')) t(myname) order by convertto(myname,'GBK'); myname 陈五 李四 张三 (3 rows) 通过指定排序规则collact 来实现汉字按拼音进行排序。 plaintext teledb