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

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

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

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 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年前 评论

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