、私は得ることができる最善のことは、これらの2つのバージョンである:(それはフランス語のだ、plzは気にしないでください)
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
そして:
これにより
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
、私が取得できます。
- フォーラムのすべての基本情報(タイトル、ステータスが...)
を
- 直接フォーラムにリンクされているトピックの数
- フォーラムの子供たちにリンクされているトピックの数(意味:他のフォーラム)
- フォーラム
- ポストの数での話題で投稿数最後のポスト/話題のフォーラムの子供たち
- 情報(ID、日付とユーザーのに関する情報)のトピックは、フォーラム
には、少なくとも私の意見では、少し厄介だ、と私はかなりよより良い方法とそれを実現するためのより良い方法があることは確かですが、私はfiできません方法を見つけ出す。
驚くべきことに、私にとって少なくとも2番目のバージョンは、より早くなります。
誰かがこれを気に入らなければならない考えがある場合は、私は提案することができます。その間、それは私の機能になります!