yii2 mysql根据多个字段的数据计算排序

时间:2024-12-12 17:33:50

mysql根据多个字段的数据计算排序

select *,num1+num2*10+num3*100 num from $tableName  order by num desc

yii2框架活动记录activeRecord添加默认字段

$query =(new \yii\db\Query())
        ->select([
   'table.*',
          new Expression("'身份证' id_no_type")
  ])
->from(['table' => $this->tableName()])

yii2框架活动记录activeRecord添加计算字段

$query =(new \yii\db\Query())
        ->select([
   'table.*',
          new Expression("views_num+collect_num*10+share_num*100 new_sort")
  ])
->from(['table' => $this->tableName()])