[英]How do i write the following query in php Yii2?
select print_date as pdate, count(print_date) as pcount from cards where print_date BETWEEN DATE_SUB(CURRENT_DATE(), INTERVAL 6 DAY) and CURRENT_DATE() group by print_date 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 分组
*********with one more condition where created_by=>Yii::$app->user->identity; *********还有一个条件 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();
When i execute the above query i get the results but when i replace 2021-03-01 with DATE_SUB('CURRENT_DATE()',INTERVAL 7 DAYS) i get an empty array[0]当我执行上述查询时,我得到了结果,但是当我用 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.