这是我的代码:DB::table('admins')->whereIn('a_id', function ($query) { $query->select('a_id')->fromRaw('( select a_id, row_number() over( partition by a_username order by a_username) as row_num from admins ) t') ->whereRaw('row_num > 1'); })->delete();});这是 laravel 为我查询的内容:delete from `admins` where `a_id` in (select `a_id` from ( select a_id, row_number() over(partition by a_username order by a_username) as row_num from admins ) t where row_num > 1));如您所见,查询末尾有一个“)”,如果我将其删除,它会起作用,但我该怎么做呢??我是从这个错误中得到的:Illuminate\Database\QueryExceptionSQLSTATE[42000]: Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause (SQL: delete from `admins` where `a_id` in (select `a_id` from ( select a_id, row_number() over( partition by a_username order by a_username) as row_num from admins ) t where row_num > 1))有了这个错误,我发现这里在查询末尾有一个额外的“)”,它不是我的代码,而且 laravel 似乎把它弄错了。谁知道我该如何删除它,或者如果问题出在代码中,我在代码中犯了什么错误。我的 laravel 版本是: 7.9.2 而我的 PHP 版本是 7.4.5 。
1 回答
千万里不及你
TA贡献1784条经验 获得超9个赞
尝试改变
strict => true to false in config/database.php in connections => mysql.
检查它是否有帮助。
- 1 回答
- 0 关注
- 102 浏览
添加回答
举报
0/150
提交
取消