我试图使CakePHP字符串排序,但我有一些错误与此。我有C.110, C.100.1,…, C.100.8。
当我尝试使用:
ORDER BY CAST(plane_accounts.code AS DECIMAL(10,5))
MySQL返回如下:
C.110
C.110.8
C.110.1
C.100.2
有人知道怎么解决这个问题吗?谢谢你的帮助。
不需要强制转换,对code
字段进行普通的ASC排序应该就可以了:
$this->PlaneAccount->find('all', array(
'order' => array(
'PlaneAccount.code' => 'ASC'
)
));
或者在普通MySQL语法中:
SELECT `code` FROM `plane_accounts` ORDER BY `code` ASC;