2019-04-10 09:29:12 2154次浏览 2条回答 0 悬赏 10 金钱

大家好,我这个 sql 语句的 if 判断这样写正确吗?

$res_list1  = $a =  (new Query())->from('banner_click as bc')
    ->select(['bc.*,DATE_FORMAT(bc.add_time,"%Y-%m-%d") as add_time,b.banner_name,b.position,count(*) as count'])
    ->leftJoin('banner as b','b.banner_id = bc.banner_id')
    ->where(['>', "bc.add_time", $start_time])
    ->andWhere(['<', "bc.add_time", $end_time]);
    if($banner_type !== 0){
        $res_list1->andWhere(['=', "b.position", $banner_type]);
    }
    $res_list1->groupBy(['DATE_FORMAT(bc.add_time,"%Y-%m-%d")','bc.banner_id'])
    ->all(\Yii::$app->db_activity);
//echo $res_list1->createCommand()->getRawSql();die;

最佳答案

  • Holle word 发布于 2019-04-10 14:07 举报

    $a = (new Query())->from('banner_click as bc')

    ->select(['bc.*,DATE_FORMAT(bc.add_time,"%Y-%m-%d") as add_time,b.banner_name,b.position,count(*) as count'])
    ->leftJoin('banner as b','b.banner_id = bc.banner_id')
    ->where(['>', "bc.add_time", $start_time])
    ->andWhere(['<', "bc.add_time", $end_time]);
    if($banner_type != 0){
        $a->andWhere(['=', "b.position", $banner_type]);
    }
    $res_list1 =  $a->groupBy(['DATE_FORMAT(bc.add_time,"%Y-%m-%d")','bc.banner_id'])
    ->all(\Yii::$app->db_activity);
    //echo $res_list1->createCommand()->getRawSql();die;
    
您需要登录后才可以回答。登录 | 立即注册
PHP学院的中学生
副总裁

PHP学院的中学生

注册时间:2018-10-23
最后登录:2024-09-23
在线时长:168小时13分
  • 粉丝29
  • 金钱4725
  • 威望30
  • 积分6705

热门问题