繁体   English   中英

我如何在 php Yii2 中编写以下查询?

[英]How do i write the following query in php Yii2?

select print_date as pdate, count(print_date) as pcount from card where print_date BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 6 DAY) 和 CURRENT_DATE() 按 print_date 分组

*********还有一个条件 created_by=>Yii::$app->user->identity;

 $rows = (new \yii\db\Query())
        ->select(['print_date AS pdate','count(print_date) as pcount'])
        ->from('cards')
        ->andwhere(['between','print_date','2021-03-01','CURRENT_DATE()'])
        ->andWhere(['created_by'=>Yii::$app->user->identity->id])
        ->groupBy('print_date')
        ->all();

当我执行上述查询时,我得到了结果,但是当我用 DATE_SUB('CURRENT_DATE()',INTERVAL 7 DAYS) 替换 2021-03-01 时,我得到一个空数组 [0]

    $rows = (new \yii\db\Query())
        ->select(['print_date AS pdate','count(print_date) as pcount'])
        ->from('cards')
        ->andwhere(['between','print_date','DATE_SUB(CURRENT_DATE(), INTERVAL 6 DAY)','CURRENT_DATE()'])
        ->andWhere(['created_by'=>Yii::$app->user->identity->id])
        ->groupBy('print_date')
        ->all();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM