Mam databazi zavodu a v tabulce mam seznam jezdcu a jejich vysledku (pozici a vypocitam si kolik ziskali bodu), potrebuji z teto tabulky pro kazdeho jezdce vybrat 7 nejlepsich vysledku a ty secist a seradit
Povedlo se me udelat dotaz ktery tohle umi pro jednoho konkretniho jezdce
SELECT SUM(Points) AS Celkem FROM
(
SELECT
Calendar2011.ID AS Zavod,
IF(Position>0 AND Position<11,(SELECT Points FROM Points2011 WHERE ID=Position LIMIT 1)*(SELECT Coefficient FROM Calendar2011 WHERE ID=Zavod LIMIT 1),0) AS Points
FROM Zavod2011
INNER JOIN Calendar2011 ON Zavod2011.ZavodID=Calendar2011.ID
INNER JOIN Drivers ON Zavod2011.DriverID=Drivers.ID
WHERE Drivers.ID=54453 ORDER BY Points DESC LIMIT 7
) AS Jeden
kdyz se ale snazim z druhe tabulky kde mam seznam jezdcu spoustet tento prikaz pro kazde ID tak mam problem
SELECT ID AS SuperID,
(
SELECT SUM(Points) AS Celkem FROM
(
SELECT
Calendar2011.ID AS Zavod,
IF(Position>0 AND Position<11,(SELECT Points FROM Points2011 WHERE ID=Position LIMIT 1)*(SELECT Coefficient FROM Calendar2011 WHERE ID=Zavod LIMIT 1),0) AS Points
FROM Zavod2011
INNER JOIN Calendar2011 ON Zavod2011.ZavodID=Calendar2011.ID
INNER JOIN Drivers ON Zavod2011.DriverID=Drivers.ID
WHERE Drivers.ID=SuperID ORDER BY Points DESC LIMIT 7
) AS top7
) AS Celkem
FROM Drivers ORDER BY Celkem DESC
#1054 - Unknown column 'SuperID' in 'where clause'
Jedine co me napada je udelat si tabulku prubeznych souctu, v PHP bych mel script ktery by ten muj dotaz spustil pro kazdeho jezdce, ale radeji bych to primo v sql.