Ich habe ein Problem und weiß nicht, wie es zu beheben. Ich brauche ein bestimmtes Objekt aus wählen wie { "iso": "UA", "Geschichten": 122, "title": Ukraine } erhaltenLaravel Query Builder, mit Problem
, so habe ich eine SQL-Abfrage
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
und es funktioniert gut, so dass ich versuchen, diese Abfrage Laravel QB neu zu schreiben:
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();
und dann bekomme ich einen Fehler
Syntaxfehler oder Zugriffsverletzung: 1055 'way.countries.id' ist nicht in GROUP BY
und in zeigt mir eine SQL-Zeichenfolge, dass ich erfolgreich in mysql
http://stackoverflow.com/a/40918649/1745672 – Mihai
post als Antwort, ich werde es markieren! Sie sparen meine Nacht) danke – mikrafizik