- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试查找今天创建的所有记录,并以列 functional_id
的 1 开头。
我得到以下语法错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE functional_id LIKE "1%"' at line 1 (SQL: select count(*) as aggregate from
image_requests
where date(created_at
) = 2019-01-24 00:00:00 and WHERE functional_id LIKE "1%")
我的 Eloquent 代码:
$counter = ImageRequest::whereDate('created_at', $date)->whereRaw('WHERE functional_id LIKE "1%"')->count();
最佳答案
这应该有效:
$counter = ImageRequest::whereDate('created_at', $date)
->where('functional_id', 'like', '1%')
->count();
我认为问题在于额外的 "
。但是,在这种情况下不需要使用 whereRaw()
。where()
绰绰有余,而且不太容易出现这样的错误 :)
编辑:根据您的评论,如果您想要检查第十二个字符是否为 1
,以下应该可行:
$counter = ImageRequest::whereDate('created_at', $date)
->whereRaw('SUBSTRING(funtional_id, 12, 1) = 1')
->count();
关于php - Laravel 5.6 Eloquent whereDate 和 WhereRaw 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54344295/
我正在使用 Laravel 5.5,我需要形成一个查询,其中只应匹配日期时间列的日期部分,相当于 date(date_col)='2018-01-01'事物。我如何以 Eloquent 方式实现这一目
(很抱歉提前发了这么长的帖子) 我正在将我的应用程序从 Laravel 5.2 升级到 5.4,并且从今天早上开始就一直卡在这个问题上。出于某种原因,我使用 Eloquent “whereDate”选
我正在尝试查找今天创建的所有记录,并以列 functional_id 的 1 开头。 我得到以下语法错误: SQLSTATE[42000]: Syntax error or access violat
谁能告诉我这个查询有什么问题? $orderdaytimes = OrderDayTime::whereColumn([ ['date','>=',$start
我是一名优秀的程序员,十分优秀!