数据库是时间戳格式 ,要求查询数据按日期年月日格式分组,为什么查询出来还是按时间戳分组

数据库是时间戳格式 ,要求查询数据按日期年月日格式分组,为什么查询出来还是按时间戳分组

数据库是时间戳格式 ,要求查询数据按日期年月日格式分组,为什么查询出来还是按时间戳分组
求大神指点

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 3

你group by 的是 u.create_time

4年前 评论
summer-hot (楼主) 4年前
Kamicloud (作者) 4年前

给你个参考吧

        $query = function ($query) use ($startAt, $endAt) {
            /** @var Builder $query */
            $success = NotificationSendRecordStatus::SUCCESS;
            return $query->select([
                'template_id',
                DB::raw('count(*) as send_records_count'),
                DB::raw("count(case when status = {$success} then 1 end) as send_success_records_count"),
                DB::raw("count(case when status <> {$success} then 1 end) as send_failed_records_count"),

                DB::raw('count(case when landing_times > 0 then 1 end) as landing_records_count'),
                DB::raw("date_format(created_at, '%Y-%m-%d') as created_date"),
                DB::raw('count(distinct user) as users_count'),
            ])->whereBetween('created_at', [$startAt, (clone $endAt)->endOfDay()])
                ->groupBy('template_id', DB::raw('created_date'));
        };
4年前 评论

groupBy("from_unixtime(u.create_time,'%Y-%m-%d')")

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!