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

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

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

《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 3

你group by 的是 u.create_time

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

给你个参考吧

        $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'));
        };
5年前 评论

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

5年前 评论

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