gpt4 book ai didi

php - MySQL 语法错误 SQL 错误 [1064] [42000] : You have an error in your SQL syntax

转载 作者:行者123 更新时间:2023-11-28 23:11:20 25 4
gpt4 key购买 nike

<分区>

所以我有以下代码:

public function scopePopular($query, $limit = 10)
{
$query->leftJoin(DB::raw('(SELECT COUNT(id) visits, UNIQUE(ip_address) FROM `visitors`) visitors'), function($join)
{
$join->on('visitors.visitorable_id', '=', 'db885a18-f0b7-4f55-9d93-743fbb5d9c94');
$join->where('visitors.visitorable_type', '=', 'App\Profile');
});

return $query;
}

产生以下查询:

select * from `profiles` inner join `profile_genres` on `profiles`.`id` = `profile_genres`.`profile_id` left join (SELECT COUNT(id) visits, UNIQUE(ip_address) FROM `visitors`) visitors on `visitors`.`visitorable_id` = `db885a18-f0b7-4f55-9d93-743fbb5d9c94` and `visitors`.`visitorable_type` = ? where `profile_genres`.`genre_id` = ? and `profiles`.`deleted_at` is null

这个查询似乎没有工作,我猜是由于语法错误,并且 MYSQL 在其错误消息中并不完全具体。

SQL Error [1064] [42000]: 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 'UNIQUE(ip_address) FROM visitors)on visitors.visitorable_id = 'db885a18-f0' at line 1

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