這是我的代碼: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 為我查詢的內(nèi)容: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))有了這個錯誤,我發(fā)現(xiàn)這里在查詢末尾有一個額外的“)”,它不是我的代碼,而且 laravel 似乎把它弄錯了。誰知道我該如何刪除它,或者如果問題出在代碼中,我在代碼中犯了什么錯誤。我的 laravel 版本是: 7.9.2 而我的 PHP 版本是 7.4.5 。
1 回答

千萬里不及你
TA貢獻1784條經(jīng)驗 獲得超9個贊
嘗試改變
strict => true to false in config/database.php in connections => mysql.
檢查它是否有幫助。
- 1 回答
- 0 關(guān)注
- 139 瀏覽
添加回答
舉報
0/150
提交
取消