大家好,我这个 SQL 语句的 if 判断这样写正确吗? [ 2.0 版本 ]
大家好,我这个 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学院的中学生 觉得很赞
其他 1 个回答
PHP学院的中学生
注册时间:2018-10-23
最后登录:2024-09-23
在线时长:168小时13分
最后登录:2024-09-23
在线时长:168小时13分
- 粉丝29
- 金钱4725
- 威望30
- 积分6705