今天遇到要中文排序的问题。直接用order by name 发现不行。查找资料原来是编码问题,转成gb2312即可。
select name from test1 order by convert(name using gb2312) asc;
在thinkphp 中写法为:
$Customer->distinct(true)->field("customer_name")->order("convert(customer_name using gb2312) ")->select();
本文介绍了解决中文排序问题的方法。通过将字段转换为GB2312编码,可以在SQL查询中实现正确的中文排序。此外,还提供了ThinkPHP框架下的具体实现案例。
今天遇到要中文排序的问题。直接用order by name 发现不行。查找资料原来是编码问题,转成gb2312即可。
select name from test1 order by convert(name using gb2312) asc;
在thinkphp 中写法为:
$Customer->distinct(true)->field("customer_name")->order("convert(customer_name using gb2312) ")->select();

被折叠的 条评论
为什么被折叠?