Nach einigen Stunden Arbeit (zu viele Stunden, TBH), das Beste, was ich bekommen konnte, ist diese 2 Versionen: (in französisch ist, PLZ nicht stören)
Version 1:
SELECT DISTINCT fo.fo_id, fo.fo_parent, fo.fo_type, fo.fo_statut, fo.fo_ordre, fo.fo_titre,
COUNT(DISTINCT fot.fot_id) as nbr_topics,
COUNT(DISTINCT fot2.fot_id) as nbr_topics_enfants,
COUNT(DISTINCT fop.fop_id) as nbr_posts,
COUNT(DISTINCT fop2.fop_id) as nbr_posts_enfants,
fopi.fop_id, fopi.fop_timestamp, fopi.fop_fotid, fopi.fop_uid, u.u_pseudonyme, u.u_avatar, foti.fot_id, foti.fot_titre
FROM fo_forums as fo
LEFT JOIN fo_forums as foe ON foe.fo_parent = fo.fo_id
LEFT JOIN fo_forums as fope ON fope.fo_parent = foe.fo_id
LEFT JOIN fo_topics as fot ON (fot.fot_foid = fo.fo_id)
LEFT JOIN fo_posts as fop ON fop.fop_fotid = fot.fot_id
LEFT JOIN fo_topics as fot2 ON (fot2.fot_foid = foe.fo_id OR fot2.fot_foid = fope.fo_id)
LEFT JOIN fo_posts as fop2 ON fop2.fop_fotid = fot2.fot_id
LEFT JOIN fo_posts as fopi ON fopi.fop_id = (SELECT MAX(fot_derniermsg) FROM fo_topics WHERE (fot_foid = fo.fo_id))
LEFT JOIN fo_topics as foti ON foti.fot_id = fopi.fop_fotid
LEFT JOIN u_individus as u ON u.u_id = fopi.fop_uid
GROUP BY fo.fo_id
Und:
Version 2
SELECT DISTINCT fo.fo_id, fo.fo_parent, fo.fo_type, fo.fo_statut, fo.fo_ordre, fo.fo_titre,
(SELECT COUNT(fot.fot_id) FROM fo_topics as fot WHERE fot.fot_foid = fo.fo_id) as nbr_topics,
(SELECT COUNT(fot.fot_id) FROM fo_topics as fot
LEFT JOIN fo_forums as foe ON foe.fo_id IS NOT NULL
LEFT JOIN fo_forums as fope ON fope.fo_parent = foe.fo_id
WHERE ((foe.fo_parent = fo.fo_id) AND (fot.fot_foid = foe.fo_id OR fot.fot_foid = fope.fo_id))
) as nbr_topics_enfants,
(SELECT COUNT(fop.fop_id) FROM fo_posts as fop JOIN fo_topics as fot ON fot.fot_id = fop.fop_fotid WHERE fot.fot_foid = fo.fo_id) as nbr_posts,
(SELECT COUNT(fop.fop_id) FROM fo_topics as fot
LEFT JOIN fo_forums as foe ON foe.fo_id IS NOT NULL
LEFT JOIN fo_forums as fope ON fope.fo_parent = foe.fo_id
LEFT JOIN fo_posts as fop ON fop.fop_fotid = fot.fot_id
WHERE ((foe.fo_parent = fo.fo_id) AND (fot.fot_foid = foe.fo_id OR fot.fot_foid = fope.fo_id))
) as nbr_posts_enfants,
fopi.fop_id, fopi.fop_timestamp, fopi.fop_fotid, fopi.fop_uid, u.u_pseudonyme, u.u_avatar, foti.fot_id, foti.fot_titre
FROM fo_forums as fo
LEFT JOIN fo_posts as fopi ON fopi.fop_id = (SELECT MAX(fot_derniermsg) FROM fo_topics WHERE (fot_foid = fo.fo_id))
LEFT JOIN fo_topics as foti ON foti.fot_id = fopi.fop_fotid
LEFT JOIN u_individus as u ON u.u_id = fopi.fop_uid
Damit kann ich:
- alle grundlegenden Informationen des Forums (Titel, Status ...)
- die Anzahl der Themen direkt mit dem Forum verbunden
- die Anzahl der Themen des Forums Kinder verbunden (das heißt: andere Foren)
- die Zahl der Stellen in den Themen des Forums
- die Anzahl der Beiträge in die Themen des Forums Kinder
- die Informationen (id, Datum und Infos des Benutzers) des letzten Beitrag/Themen im Forum
Es ist ein wenig chaotisch, zumindest meiner Meinung nach, und ich bin ziemlich Sicher, es gibt einen schöneren Weg und eine bessere Leistung, aber ich kann nicht finde heraus, wie.
Ziemlich erstaunlich, für mich zumindest, ist die zweite Version schneller als die erste.
Wenn jemand eine Idee hat, dies zu verbessern, bin ich offen für Vorschläge. In der Zwischenzeit wird es meine Aufgabe sein!