Laravel whereMonth 查询问题?

我希望使用whereMonth来查询相对应的数据 可是结果不如我所愿

         //  Laravel5.7
        $lastMonthVisitor = StatisticsUserModel::query()
            ->whereMonth('statistics_time',8) // 我准备查询8月份的数据
            ->sum('new_create_visitor_user');
        print_r($lastMonthVisitor);

数据库分别存储了两条数据
statistics_time列
2022-08-01
2021-08-01
new_create_visitor_user列
26
52

我想查的是26这条数据 当我使用以上的sql进行查询的时候 查出来了78 显然 这不是我想要的 请问这是怎么回事? 是我写法有误吗?

CollinAi
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

whereYear是不是应该加上 :joy:

3年前 评论
讨论数量: 3

whereYear是不是应该加上 :joy:

3年前 评论

不加个年,也不知道你查哪一年的数据呀

$lastMonthVisitor = StatisticsUserModel::query()
            ->whereYear('statistics_time',2022)
            ->whereMonth('statistics_time',8)
            ->sum('new_create_visitor_user');
3年前 评论
Efrain (楼主) 3年前

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