Laravel统计一段时间间隔的数据方法_php实例

来源:脚本之家  责任编辑:小易  

www.zgxue.com防采集请勿采集本网。

获取七天以前到现在的数据:

最佳答案看平台安全指数要看它的安全保障体系是不是完善,从安全保障方面来说旺财谷拥有六重安全保障,业务定位保障、法律合规保障、资金托管保障、多级风控保障、收益重

$days = Input::get('days', 7);$range = \Carbon\Carbon::now()->subDays($days);$stats = User::where('created_at', '>=', $range) ->groupBy('date') ->orderBy('date', 'DESC') ->get([ DB::raw('Date(created_at) as date'), DB::raw('COUNT(*) as value') ]);

问题说明: 我被罚过4次,两次违章停车,一次违章转弯,还有一次高峰时间占用公共汽

SELECT sum(case when `EmailSource`='FM' then 1 else 0 end) as FM_Statistic,sum(case when `EmailSource`='UOC' then 1 else 0 end) as UOC_Statistic,sum(case when `EmailSource`='OC' then 1 else 0 end) as OC_Statistic,DATE_FORMAT(Date,'%Y-%m-%d') AS `DateTime` FROM `user_performance` WHERE Email != '' AND Email != 'TOTAL'AND (DATE_FORMAT(Date,'%Y-%m-%d') >= DATE_FORMAT('2011-02-5','%Y-%m-%d')) AND (DATE_FORMAT(Date,'%Y-%m-%d') <= DATE_FORMAT('2011-03-07','%Y-%m-%d')) GROUP BY `Date`

问题说明: 我想在一天24小时之内,每一个小时统计一下数据0-1 1-2 2-3 时间格式

public function getNumber() { $data = []; $customers = Customer::all(['id', 'customer_type', 'created_at']); #今天数据 $data['customer_today'] = Customer::where('customer_type', 1)->where('created_at', Carbon::today())->count(); $data['teacher_today'] = Customer::where('customer_type', 2)->where('created_at', Carbon::today())->count(); #昨天数据 $data['customer_yesterday'] = Customer::where('customer_type', 1)->where('created_at', Carbon::yesterday())->count(); $data['teacher_yesterday'] = Customer::where('customer_type', 2)->where('created_at', Carbon::yesterday())->count(); $data['today'] = $data['customer_today'] + $data['teacher_today']; $data['yesterday'] = $data['customer_yesterday'] + $data['teacher_yesterday']; // 本周数据 $this_week = [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()]; $data['customer_this_week'] = Customer::where('customer_type', 1)->whereBetween('created_at', $this_week)->count(); $data['teacher_this_week'] = Customer::where('customer_type', 2)->whereBetween('created_at', $this_week)->count(); // 上周数据 $last_week = [Carbon::now()->startOfWeek()->subWeek(), Carbon::now()->endOfWeek()->subWeek()]; $data['customer_last_week'] = Customer::where('customer_type', 1)->whereBetween('created_at', $last_week)->count(); $data['teacher_last_week'] = Customer::where('customer_type', 2)->whereBetween('created_at', $last_week)->count(); $data['this_week'] = $data['customer_this_week'] + $data['teacher_this_week']; $data['last_week'] = $data['customer_last_week'] + $data['teacher_last_week']; // 本月数据 $data['customer_this_month'] = Customer::where('customer_type', 1)->whereMonth('created_at', Carbon::now()->month)->count(); $data['teacher_this_month'] = Customer::where('customer_type', 2)->whereMonth('created_at', Carbon::now()->month)->count(); // 上月数据 $data['customer_last_month'] = Customer::where('customer_type', 1)->whereMonth('created_at', Carbon::now()->subMonth()->month)->count(); $data['teacher_last_month'] = Customer::where('customer_type', 2)->whereMonth('created_at', Carbon::now()->subMonth()->month)->count(); $data['this_month'] = $data['customer_this_month'] + $data['teacher_this_month']; $data['last_month'] = $data['customer_last_month'] + $data['teacher_last_month']; // 本年数据 $data['customer_this_year'] = Customer::where('customer_type', 1)->whereYear('created_at', Carbon::now()->year)->count(); $data['teacher_this_year'] = Customer::where('customer_type', 2)->whereYear('created_at', Carbon::now()->year)->count(); $data['today_login_users'] = LoginLog::whereDate('created_at', '=', Carbon::today()) ->groupBy('customer_id') ->orderBy('customer_id') ->count(); $data['yesterday_login_users'] = LoginLog::whereDate('created_at', '=', Carbon::yesterday()) ->groupBy('customer_id') ->orderBy('customer_id') ->count(); $data['this_month_login_users'] = LoginLog::whereMonth('created_at', Carbon::now()->month) ->groupBy('customer_id') ->orderBy('customer_id') ->count(); $data['last_month_login_users'] = LoginLog::whereMonth('created_at', Carbon::now()->subMonth()->month) ->groupBy('customer_id') ->orderBy('customer_id') ->count(); return $data; }

问题说明: 时间 2 2010-06-23 01 1 2010-06-23 02SQL语句这么写啊。。。。。。

public function numberCount() { $days = request('days', 7); $range = Carbon::today()->subDays($days); $day_stats = Customer::where('created_at', '>=', $range) ->groupBy('date') ->orderBy('date', 'DESC') ->get([ \DB::raw('DATE_FORMAT(created_at,\'%Y-%m-%d\') as date,SUM(CASE WHEN customer_type = 1 THEN 1 ELSE 0 END) AS customer,SUM(CASE WHEN customer_type = 2 THEN 1 ELSE 0 END) AS teacher'), ]) ->toJSON(); $week_stats = Customer::groupBy('week') ->orderBy('week', 'DESC') ->get([ \DB::raw('DATE_FORMAT(created_at,\'%Y W%u\') as week,SUM(CASE WHEN customer_type = 1 THEN 1 ELSE 0 END) AS customer, SUM(CASE WHEN customer_type = 2 THEN 1 ELSE 0 END) AS teacher'), ]) ->toJSON(); // dd($week_stats); // \DB::enableQueryLog(); $month_stats = Customer::groupBy('month') ->orderBy('month', 'DESC') ->get([ \DB::raw('DATE_FORMAT(created_at,\'%Y-%m\') as month,SUM(CASE WHEN customer_type = 1 THEN 1 ELSE 0 END) AS customer,SUM(CASE WHEN customer_type = 2 THEN 1 ELSE 0 END) AS teacher'), ]) ->toJSON(); // dd(\DB::getQueryLog()); // dd($week_stats, $month_stats); $data = $this->getNumber(); // dd($day_stats, $week_stats, $month_stats, $data); return view('admin.numberCount', compact('day_stats', 'week_stats', 'month_stats', 'data')); }

问题说明: 输入textbox中一个数字, 然后按按钮,得到的是now的日期 - textbox 中天数

效果图:

以上这篇Laravel统计一段时间间隔的数据方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持真格学网。

内容来自www.zgxue.com请勿采集。


  • 本文相关:
  • laravel 时间格式转时间戳的例子
  • laravel timestamps 设置为unix时间戳的方法
  • php批量更改数据库表前缀实现方法
  • thinkphp下ueditor的使用方法详解
  • php实现粘贴截图并完成上传功能
  • 简单解决新浪sae无法上传文件的问题
  • php目录操作实例代码
  • php中set error handler函数用法小结
  • 浅析php设计模式之数据对象映射模式
  • thinkphp3.2.3框架邮件发送功能图文实例详解
  • php定时执行任务实现方法详解(timer)
  • php爬取天猫和淘宝商品数据
  • laravel怎么实现每隔一段时间去差数据库
  • 高一的内容:ΔS=aT^2此公式是如何得出的?
  • 欧瑞莲的适用额度一段时间不用,不会减少,为什么
  • excel怎么统计一段时间范围内,中包含的时间出现次数?
  • 关注旺财谷有一段时间了,大家觉得旺财谷的安全指数怎么样?
  • 统计一下大家被JCSS罚过多少次?
  • Sql时间间隔
  • SQL 统计 一段时间 按每小时统计 记录的数量
  • vb.net date 的 计算
  • ...标签中分别是两个日期,如何用宏计算其的间隔多少天?如果时间是...
  • 网站首页网页制作脚本下载服务器操作系统网站运营平面设计媒体动画电脑基础硬件教程网络安全php基础php技巧php实例php文摘php模板首页php编程laravel 时间格式转时间戳的例子laravel timestamps 设置为unix时间戳的方法php批量更改数据库表前缀实现方法thinkphp下ueditor的使用方法详解php实现粘贴截图并完成上传功能简单解决新浪sae无法上传文件的问题php目录操作实例代码php中set error handler函数用法小结浅析php设计模式之数据对象映射模式thinkphp3.2.3框架邮件发送功能图文实例详解php定时执行任务实现方法详解(timer)php爬取天猫和淘宝商品数据php获取数组长度的方法(有实例)微信公众平台实现获取用户openid教你如何使用php session使用php生成二维码的两种方法(带php发送get、post请求的6种方法简php中把stdclass object转array的微信公众平台网页授权获取用户基laravel框架数据库curd操作、连贯php删除数组中空值的方法介绍php从数组中删除元素的四种方法实form表单传递数组数据、php脚本接收的实例laravel 默认邮箱登录改成用户名登录的实简单的php留言本实例代码php实现mysql封装类示例php实现文件上传功能实例代码thinkphp框架无限级栏目的排序功能实现方laravel多用户认证系统示例详解在laravel的model层做数据缓存的实现codeigniter中测试通过的分页类示例php解析url并得到url中的参数及获取url参
    免责声明 - 关于我们 - 联系我们 - 广告联系 - 友情链接 - 帮助中心 - 频道导航
    Copyright © 2017 www.zgxue.com All Rights Reserved