Autor | Zpráva | ||
---|---|---|---|
Manny Profil |
#1 · Zasláno: 22. 12. 2015, 12:59:47
Nedaří se mi zprovoznit následující select
SELECT c.id, c.nazev, c.popis, if(c.pocethlasovani>0, round(c.celkovaznamka/c.pocethlasovani, 2), '0') AS znamka, GROUP_CONCAT(l.name_label) AS labelgroup FROM ".PREFIX."comics c LEFT JOIN ".PREFIX."author_to_comics atc ON atc.id_comics = c.id LEFT JOIN ".PREFIX."author a ON a.id = atc.id_author LEFT JOIN ".PREFIX."trans_to_comics ttc ON ttc.id_comics = c.id LEFT JOIN ".PREFIX."translator t ON t.id = ttc.id_trans LEFT JOIN ".PREFIX."label_to_comics ltc ON ltc.id_comics = c.id LEFT JOIN ".PREFIX."label l ON l.id_label = ltc.id_label GROUP BY ltc.id_comics WHERE c.id is not null ".$db." LIMIT ".($od-1).", ".ROWS; Výsledkem je 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 'WHERE c.id is not null ORDER BY c.id desc LIMIT 0, 10' at line 10
Přepokládám chybu v GROUP, ale nevím podle čeho bych měl seskupovat. |
||
Kajman Profil |
V selectu patří group by až za where klauzuli. V group by by měly být uvedené alespoň všechny sloupce, které nejsou obalené agregační funkcí, jinak to může na některých konfiguracích mysql havarovat.
WHERE c.id is not null ".$db." GROUP BY c.id, c.nazev, c.popis, c.pocethlasovani, c.pocethlasovani LIMIT ".($od-1).", ".ROWS; |
||
Manny Profil |
#3 · Zasláno: 22. 12. 2015, 13:27:58
Pořád chyba
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 'GROUP BY c.id, c.nazev, c.popis, c.pocethlasovani, c.pocethlasovani LIMIT 0,' at line 10 |
||
Kajman Profil |
#4 · Zasláno: 22. 12. 2015, 13:32:30
Vypište si celý sestavený dotaz (tedy s náhradou záhadné proměnné $db). Chyba bude asi kousek před tím group by.
|
||
Manny Profil |
#5 · Zasláno: 22. 12. 2015, 13:40:29
V proměnné
$db není nic záhadného, jenom řazení
celý dotaz: SELECT c.id, c.nazev, c.popis, if(c.pocethlasovani>0, round(c.celkovaznamka/c.pocethlasovani, 2), '0') AS znamka, GROUP_CONCAT(l.name_label) AS labelgroup FROM listo_comics c LEFT JOIN listo_author_to_comics atc ON atc.id_comics = c.id LEFT JOIN listo_author a ON a.id = atc.id_author LEFT JOIN listo_trans_to_comics ttc ON ttc.id_comics = c.id LEFT JOIN listo_translator t ON t.id = ttc.id_trans LEFT JOIN listo_label_to_comics ltc ON ltc.id_comics = c.id LEFT JOIN listo_label l ON l.id_label = ltc.id_label WHERE c.id is not null ORDER BY c.id desc GROUP BY c.id, c.nazev, c.popis, c.pocethlasovani, c.pocethlasovani LIMIT 0, 10 |
||
Kajman Profil |
#6 · Zasláno: 22. 12. 2015, 19:11:52
ORDER BY patří až za GROUP BY, viz syntaxe SELECTu
dev.mysql.com/doc/refman/5.7/en/select.html |
||
Časová prodleva: 7 let
|
0