ThinkPHP 查询统计:z_data_days 表中 datetime 字段的 count 值
可以使用ThinkPHP的查询构建器来实现该查询语句。首先需要在控制器中引入模型类,然后使用查询构建器的方法进行查询。\n\nphp\nuse app\model\ZDataDays; // 假设模型类为ZDataDays\n\npublic function queryStatistics()\n{\n $count_2023_09_Ln_Meet_Standards_1 = ZDataDays::where('datetime', 'like', '2023-09%')\n ->where('Ln_Meet_Standards', 1)\n ->count();\n \n $count_2023_09_Ln_Meet_Standards_0 = ZDataDays::where('datetime', 'like', '2023-09%')\n ->where('Ln_Meet_Standards', 0)\n ->count();\n \n $count_2023_09_Ld_Meet_Standards_0 = ZDataDays::where('datetime', 'like', '2023-09%')\n ->where('Ld_Meet_Standards', 0)\n ->count();\n \n $count_2023_09_Ld_Meet_Standards_0 = ZDataDays::where('datetime', 'like', '2023-09%')\n ->where('Ld_Meet_Standards', 0)\n ->count();\n \n $count_2023_08_Ln_Meet_Standards_1 = ZDataDays::where('datetime', 'like', '2023-08%')\n ->where('Ln_Meet_Standards', 1)\n ->count();\n \n $count_2023_08_Ln_Meet_Standards_0 = ZDataDays::where('datetime', 'like', '2023-08%')\n ->where('Ln_Meet_Standards', 0)\n ->count();\n \n $count_2023_08_Ld_Meet_Standards_0 = ZDataDays::where('datetime', 'like', '2023-08%')\n ->where('Ld_Meet_Standards', 0)\n ->count();\n \n $count_2023_08_Ld_Meet_Standards_0 = ZDataDays::where('datetime', 'like', '2023-08%')\n ->where('Ld_Meet_Standards', 0)\n ->count();\n \n // 返回统计结果\n return [\n 'count_2023_09_Ln_Meet_Standards_1' => $count_2023_09_Ln_Meet_Standards_1,\n 'count_2023_09_Ln_Meet_Standards_0' => $count_2023_09_Ln_Meet_Standards_0,\n 'count_2023_09_Ld_Meet_Standards_0' => $count_2023_09_Ld_Meet_Standards_0,\n 'count_2023_09_Ld_Meet_Standards_0' => $count_2023_09_Ld_Meet_Standards_0,\n 'count_2023_08_Ln_Meet_Standards_1' => $count_2023_08_Ln_Meet_Standards_1,\n 'count_2023_08_Ln_Meet_Standards_0' => $count_2023_08_Ln_Meet_Standards_0,\n 'count_2023_08_Ld_Meet_Standards_0' => $count_2023_08_Ld_Meet_Standards_0,\n 'count_2023_08_Ld_Meet_Standards_0' => $count_2023_08_Ld_Meet_Standards_0,\n ];\n}\n\n\n上述代码中,假设ZDataDays为模型类,通过where方法可以设置查询条件,count方法用于统计满足条件的记录数。最后返回一个包含统计结果的关联数组。根据实际情况,需要将模型类和返回结果的键进行适当修改。
原文地址: https://www.cveoy.top/t/topic/mFoI 著作权归作者所有。请勿转载和采集!