如何获得拉拉韦尔的平均时间 [英] How to get the average time in Laravel

查看:49
本文介绍了如何获得拉拉韦尔的平均时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取开始时间和结束时间之间的平均时间,以及我在laravel中编写sql的CUR-Time GroupBY用户名的位置,它显示了一些错误,我找不到什么那是因为我是该laravel的新手,请帮助我修复此SQL错误,然后提交我的SQL和错误消息.

I want get the the average time between start-time and end-time and Where CUR-Time GroupBY user-name i written the sql in laravel it's showing some error i can't find what's that because i'm new to that laravel please help to fix this sql error i submit the my sql and the error message.

 $avagTime = DB::table( 'active_user' )
            ->select(DB::raw('AVG(TIME_TO_SEC(acu_et) - TIME_TO_SEC(acu_at))'))
            ->where (DATE('acu_at') == ('CURDATE()'))
            ->get();[![enter image description here][1]][1]

推荐答案

问题出在您的 where 子句中.Laravel的查询生成器具有 whereDate()方法,该方法非常适合:

The issue is in your where clause. Laravel's query builder has a whereDate() method that would be perfect for this:

$avagTime = DB::table('active_user')
    ->selectRaw('AVG(TIME_TO_SEC(acu_et) - TIME_TO_SEC(acu_at))')
    ->whereDate('acu_at', today())
    ->get();


注意事项:如果您希望将where原因作为原始查询传递(例如您的示例中的内容),则需要使用类似


NB If you wanted to pass the where cause as a raw query (like you have in your example) you would need to use something like whereRaw() instead or where().

这篇关于如何获得拉拉韦尔的平均时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆