mysql-按自定义值Yii2排序
作者:互联网
我想对自定义字段上的记录进行排序,但是它给了我yii2错误,任何人都可以帮助我.
-> orderBy(player.PlayerRole,’G’,’D’,’M’,’F’);
其中G,D,M和F是自定义值.在mysql中可以正常工作,但在yii2中则不能.
我也尝试过这个
$expression = new Expression('field(player.PlayerRole,G,D,M,F)');
-> orderBy($expression)
这是完整的查询
$expression = new Expression('field(player.PlayerRole,G,D,M,F)');
return (new Query())
->select('*')
->from('tablename')`enter code here`
->orderBy(player.PlayerRole, 'G','D','M','F');
->all();
解决方法:
如本期所述:
Please read the doc carefully. orderBy takes an array, and an array element can be an Expression. So you should use $query->orderBy(array($expression)) instead of $query->orderBy($expression).
https://github.com/yiisoft/yii2/issues/553
因此请尝试-> orderBy(array($expression))
标签:yii2,sql-order-by,mysql 来源: https://codeday.me/bug/20191119/2037586.html