我在Eloquent
查询中遇到错误。
我的查询:
$mtd_hits = Usage::selectRaw("
SUM(table_hits) AS hits,
")
->where('user_id', '=', $user->id)
->whereBetween('created_at', [$from_date, $to_date])
->first();
在我的Usage
班上:
public $timestamps = true;
protected $dates = ['created_at', 'updated_at'];
我的$from_date
和$to_date
是Carbon
实例:
$from_date
:
Carbon @1556323200 {#1416 ▼
date: 2019-04-27 00:00:00.0 UTC (+00:00)
}
$to_date
:
Carbon @1558915200 {#1622 ▼
date: 2019-05-27 00:00:00.0 UTC (+00:00)
}
由于我的查询失败,因此:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from `usage` where `user_id` = ? and `created_at` between ? and ? limit 1' at line 3
(SQL: select SUM(table_hits) AS hits, from `usage` where `user_id` = 2 and `created_at` between 2019-04-27 00:00:00 and 2019-05-27 00:00:00 limit 1)
如果这是一个愚蠢的问题,请提前道歉。
答案 0 :(得分:1)
所有关于您的原始查询!
尝试从您的代码中删除,
您也可以使用->toSql()
方法查看查询