EizoPeter

EizoPeter

这家伙有点懒,还没写个性签名!

  • 财富值1500
  • 威望值0
  • 总积分1670

个人信息

  • 2019-05-13 已签到
    连续签到10天,获得了20个金钱
  • 2019-05-11 已签到
    连续签到8天,获得了20个金钱
  • 2019-05-10 已签到
    连续签到7天,获得了20个金钱
  • 回复了 的回答
    $subQuery = (new \yii\db\Query())->from('yn_goods_analyze_shop_by_day')
        ->select([
            'saleroom_sum' => 'sum(gross_margin)',
        ])
        ->where(['between', 'create_date', $startTime, $endTime])
        ->createCommand()
        ->getRawSql();
    
    $query = (new \yii\db\Query())->from('yn_goods_analyze_shop_by_day')
        ->select([
            'saleroom' => 'sum(saleroom)',
            'brand',
            'goods_name',
            'gross_margin' => 'sum(gross_margin)',
            'gross_percent' => "sum(gross_margin) / ($subQuery) * 100",
        ])
        ->where(['between', 'create_date', $startTime, $endTime])
        ->groupBy('spid');
    
    echo $query->createCommand()->getRawSql();
    

    感谢大佬

  • 赞了回答
    $subQuery = (new \yii\db\Query())->from('yn_goods_analyze_shop_by_day')
        ->select([
            'saleroom_sum' => 'sum(gross_margin)',
        ])
        ->where(['between', 'create_date', $startTime, $endTime])
        ->createCommand()
        ->getRawSql();
    
    $query = (new \yii\db\Query())->from('yn_goods_analyze_shop_by_day')
        ->select([
            'saleroom' => 'sum(saleroom)',
            'brand',
            'goods_name',
            'gross_margin' => 'sum(gross_margin)',
            'gross_percent' => "sum(gross_margin) / ($subQuery) * 100",
        ])
        ->where(['between', 'create_date', $startTime, $endTime])
        ->groupBy('spid');
    
    echo $query->createCommand()->getRawSql();
    
  • 提出了问题
    Yii 2.0 ActiveRecord 查询问题
  • 2019-05-09 已签到
    连续签到6天,获得了20个金钱
  • 回复了 的回答

    首先需要定义'enableSorting'=>true,才能让字段点击排序,即:
    `

        [
                'attribute'=>'_percent',
                'label'=>'销售占比',
                'enableSorting'=>true,
                'value'=>function($model){
                    return $model->saleroom/$model->saleroom_sum;
                }
            ],
    

    然后在Model的Search中,增加

    $query = YourModel::find()->addSelect('*')->addSelect(new Expression('saleroom/saleroom_sum as _percent'));
    
    $dataProvider->setSort([
            'attributes' => [
                '_percent' => [
                    'asc' => ['_percent' => SORT_ASC],
                    'desc' => ['_percent' => SORT_DESC],
                    'label' => 'Customer Name'
                ],
            ]
        ]);
    

    `
    这样就可以实现你想要的排序了~

    谢谢 我试试

  • 2019-05-08 已签到
    连续签到5天,获得了20个金钱
  • 2019-05-07 已签到
    连续签到4天,获得了20个金钱
经理 等级规则
1670/2000
资料完整度
20/100
用户活跃度
20/100

Ta的关注

4

Ta的粉丝

4

Ta的访客

9