gpt4 book ai didi

mysql - Laravel 查询生成器,有问题

转载 作者:搜寻专家 更新时间:2023-10-30 23:35:38 25 4
gpt4 key购买 nike

<分区>

我有一个问题,不知道如何解决。我需要从选择中获取特定对象,例如{“iso”:“UA”,“故事”:122,“标题”:乌克兰

所以我有一个sql查询

SELECT
c.iso,
locale.title as title,
(SELECT COUNT(DISTINCT s.id) FROM stories AS s WHERE s.country_id = c.id) AS stories
FROM `countries` AS c
LEFT JOIN countries_locale AS c_l ON c.id=c_l.country_id
LEFT JOIN locales AS locale ON c_l.locale_id=locale.id
WHERE locale.locale = 'en'
GROUP BY c.id
HAVING stories>0

它工作正常,所以我尝试将此查询重写为 Laravel QB:

DB::table($this->getTable())
->select(
'countries.iso as iso',
'locales.title as title',
DB::raw('(SELECT COUNT(s.id) FROM stories AS s WHERE s.country_id = countries.id) AS stories')
)
->leftJoin('countries_locale', 'countries.id', '=', 'countries_locale.country_id')
->leftJoin('locales', 'countries_locale.locale_id', '=', 'locales.id')
->where('locales.locale', \App::getLocale())
->groupBy('iso')
->having('stories', '>', 0)
->get();

然后我得到一个错误

Syntax error or access violation: 1055 'way.countries.id' isn't in GROUP BY

并向我展示了一个 sql 字符串,我可以在 mysql 中成功执行它

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