whereIn('a_id', function ($query) { $query->select(-6ren">
gpt4 book ai didi

php - 这是我的 laravel 项目中的一个额外的 ")",它为我查询 laravel

转载 作者:行者123 更新时间:2023-12-02 09:47:19 25 4
gpt4 key购买 nike

这是我的代码:

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\QueryException
SQLSTATE[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 。

最佳答案

尝试改变

 strict => true to false in config/database.php in connections => mysql.

检查它是否有帮助。

关于php - 这是我的 laravel 项目中的一个额外的 ")",它为我查询 laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61734120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com